n | O(n) | O(log n)
1 | 1 | 100
10 | 10 | 200
100 | 100 | 300
1000 | 1000 | 400
a×n = b×log(n)
var t = {
list: {
"action_buttons[0]": "View",
"action_buttons[1]": "Share",
"action_buttons[2]": "Download",
"columns[0]": "Date of Study",
"columns[1]": "Patient",
"columns[2]": "File name",
"columns[3]": "Reporting <br>Physician",
"columns[4]": "Institution"
}
};
var list = {};
var re = /^(.*?)\[(\d+)\]$/;
var match;
for (var prop in t.list) {
match = prop.match(re);
if (typeof list[match[1]] == "undefined") {
list[match[1]] = [];
}
list[match[1]][match[2]] = t.list[prop];
}
t.list = list;
console.log(t);
{…}
list: {…}
action_buttons: […]
0: "View"
1: "Share"
2: "Download"
columns: […]
0: "Date of Study"
1: "Patient"
2: "File name"
3: "Reporting <br>Physician"
4: "Institution"
<?php
$begin = new DateTime('09:00');
$end = new DateTime('21:00');
$intervals = array(
array(new DateTime('10:00'), new DateTime('10:15')),
array(new DateTime('10:15'), new DateTime('11:45')),
array(new DateTime('12:30'), new DateTime('16:00'))
);
$time = 90;
function checkInterval($begin, $end, $time) {
$intervalDiff = $begin->diff($end);
$intervalMinutes = $intervalDiff->h * 60 + $intervalDiff->i;
if ($intervalMinutes >= $time) {
echo $begin->format('H:i'), ' - ', $end->format('H:i'), "\n";
}
}
$intervalStart = $begin;
foreach ($intervals as $interval) {
checkInterval($intervalStart, $interval[0], $time);
$intervalStart = $interval[1];
}
checkInterval($intervalStart, $end, $time);
int n1 = 5, n2 = 5;
int a1[10] = {1, 4, 9, 12, 54};
int a2[] = {99, 17, 9, 8, 4};
int i1 = 0, i2 = n2-1, i = n1+n2-1;
while (i >= 0) {
if (i1 > n1-1) {
a1[i--] = a2[i2--];
} else if (i2 < 0) {
i = -1;
} else if (a1[i1] < a2[i2]) {
a1[i--] = a1[i1++];
} else {
a1[i--] = a2[i2--];
}
}
function makeBasket($sum, $prices, $result) {
if ($sum % $prices[0] == 0) {
return array_merge($result, [$sum / $prices[0]]);
}
if (count($prices) == 1) {
return false;
}
for ($i = 0; $i <= $sum / $prices[0]; $i++) {
$res = makeBasket($sum - $prices[0] * $i, array_slice($prices, 1), array_merge($result, [$i]));
if ($res != false) {
return $res;
}
}
return false;
}
$prices = array_values($accessories[$article]);
$res = makeBasket($accessoriesSum, $prices, []);
$result = [];
$i = 0;
foreach ($accessories[$article] as $key => $val) {
if (($i < count($res)) && ($res[$i] != 0)) {
$result[$key] = $res[$i];
}
$i++;
}
print_r($result);
- в пустой (мёртвой) клетке, рядом с которой ровно три живые клетки, зарождается жизнь;
- если у живой клетки есть две или три живые соседки, то эта клетка продолжает жить; в противном случае, если соседей меньше двух или больше трёх, клетка умирает («от одиночества» или «от перенаселённости»)