function divide($a, $b)
{
$divisor = $b;
if ($b > $a) {
return 0;
}
$res = 1;
while (($b + $b) <= $a) {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PATCH | |
if (column.default !== undefined) { | |
expression_1 += this.connection.driver.normalizeDefault(column); | |
} else { | |
// sqlite | |
if (_this.connection.driver instanceof AbstractSqliteDriver_1.AbstractSqliteDriver) { | |
expression_1 += "NULL" | |
// not sqlite | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_yaml { | |
local prefix=$2 | |
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') | |
sed -ne "s|^\($s\):|\1|" \ | |
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ | |
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | | |
awk -F$fs '{ | |
indent = length($1)/2; | |
vname[indent] = $2; | |
for (i in vname) {if (i > indent) {delete vname[i]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const splitByPairs = (x) => { | |
const pairsCount = x.length - 1; | |
return new Array(pairsCount).fill().map((index, val) => x.substr(val, 2)); | |
}; | |
const digitsCount = (digit, number) => number.split('').filter(num => num == digit).length; | |
const dec2bin = (dec) => { return (dec >>> 0).toString(2) }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(fn [l] | |
((fn [l acc] | |
(if (empty? l) | |
acc | |
(recur (rest l) (conj acc (first l))))) | |
l `())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// it is just a inversed version of bubble sort | |
// and elements dive to the dhische instead of go up like a bubble | |
function bubbleSort(&$array) { | |
$n = count($array); | |
for($j = 0; $j < $n; $j++) { | |
// inner loop | |
for($i = $n; $i > $j + 1; $i--) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error_reporting(E_ALL); | |
ini_set('display_errors', 1); |
function mulByAdd(a, b) {
var iter = function (res, a, b) {
if (b == 0) {
return res;
}
if (b % 2 == 0) {
return iter(res, a << 1, b >> 1)
}
return iter(res + a, a, b - 1)
<?php
$contacts = [
[
'id' => 1,
'name' => 'OAO Vorkuta',
'parent_id' => null
],
[
#Задача
Сколько нужно кирпичей, чтобы построить комнату размером A x B x C. Где:
- A - высота комнаты,
- B - ширина комнаты,
- C - длина комнаты.
Размера комнаты задаются в метрах. Толщина стены комнаты - 1 кирпич. Размеры комнаты кратны размерам кирпича, то есть не получится так, что стена будет состоять не из целого количества кирпичей. Толщиной цемента пренебрежем, и учтем что ширина кирпича вдвое меньше его длины.