<?php
/*
* Комната 0 введена для унификации алгоритма.
* Из неё можно попаст в любой выход, в неё попасть из других комнат нельзя.
*/
const NODES = [
0 => ['battleTime' => 0, 'loot' => 0],
1 => ['battleTime' => 5, 'loot' => 15],
2 => ['battleTime' => 2, 'loot' => 1],
3 => ['battleTime' => 3, 'loot' => 5],
4 => ['battleTime' => 3, 'loot' => 6],
5 => ['battleTime' => 4, 'loot' => 7],
6 => ['battleTime' => 5, 'loot' => 9],
7 => ['battleTime' => 7, 'loot' => 16],
8 => ['battleTime' => 2, 'loot' => 3],
9 => ['battleTime' => 0, 'loot' => 0],
10 => ['battleTime' => 0, 'loot' => 0],
];
const ROUTE_TIMES = [
0 => [9 => 0, 10 => 0],
1 => [2 => 1],
2 => [1 => 1, 8 => 2, 9 => 3, 4 => 1],
3 => [9 => 2, 4 => 4],
4 => [3 => 4, 2 => 1, 5 => 3],
5 => [4 => 3, 10 => 1],
6 => [10 => 4, 7 => 4],
7 => [8 => 4, 6 => 4],
8 => [2 => 2, 7 => 4, 10 => 6],
9 => [3 => 2, 2 => 3],
10 => [5 => 1, 8 => 6, 6 => 4],
];
const MAX_LIFETIME = 25;
function findRoute(array $state): array
{
$bestState = $state;
foreach (ROUTE_TIMES[$state['currentNode']] as $nextNode => $travelTime) {
$nodeTime = $state['lifetime'] + $travelTime +
(in_array($nextNode, $state['route']) ? 0 : NODES[$nextNode]['battleTime']);
if ($nodeTime > MAX_LIFETIME) {
continue;
}
$nodeState = findRoute([
'lifetime' => $nodeTime,
'currentNode' => $nextNode,
'wealth' => $state['wealth'] + (in_array($nextNode, $state['route']) ? 0 : NODES[$nextNode]['loot']),
'route' => [...$state['route'], $nextNode],
]);
if ($nodeState['wealth'] > $bestState['wealth']) {
$bestState = $nodeState;
}
}
return $bestState;
}
$state = findRoute([
'lifetime' => 0,
'currentNode' => 0,
'wealth' => 0,
'route' => [],
]);
echo "Route: ", implode(' => ', array_reverse($state['route'])), "\n";
echo "Wealth: ", $state['wealth'], "\n";
echo "Time: ", $state['lifetime'], "\n";
Route: 8 => 2 => 1 => 2 => 4 => 5 => 10
Wealth: 32
Time: 25
<meta charset="utf-8">
, то указанная вами кодировка utf-8 не совпадает с реальной кодировкой текста, отображаются вопросики.В зависимости от температуры видимый свет начинает менять цвет на разной толщине стекла.И какой видимый свет вы планируете получить, например, от человеческого тела?
<?php
function formatList(array $list): string
{
$result = '';
foreach ($list as $key => $value) {
if (!is_array($value)) {
$result .= "<li>{$key} => {$value}</li>";
continue;
}
$result .= "<li>{$key} =></li>";
foreach ($value as $item) {
$result .= formatList($item);
}
}
if ((debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'] ?? '') !== 'formatList') {
$result = "<ul>{$result}</ul>";
}
return $result;
}
print formatList($arr);
<ul><li>id => 1</li><li>name => item1</li><li>items =></li><li>id => 2</li><li>name => item2</li><li>items =></li><li>id => 3</li><li>name => item3</li><li>items =></li><li>id => 4</li><li>name => item4</li><li>items =></li><li>id => 5</li><li>name => item5</li><li>items =></li><li>id => 6</li><li>name => item6</li><li>items =></li></ul>
DELETE u.*
FROM users AS u
JOIN users AS d
ON d.login = u.login AND d.id < u.id;
ALTER TABLE users ADD UNIQUE (login);
same => n,Set(CALLERID(name)=${ICONV(866,UTF8,${CALLERID(name)})})
WITH `t` (`row`) AS (
SELECT 1
UNION SELECT 2
UNION SELECT 3
)
SELECT `row`, RAND("totally_not_random"), RAND(0), RAND(1) FROM `t`
| row | RAND("totally_not_random") | RAND(0) | RAND(1) |
| --- | -------------------------- | ------------------- | ------------------ |
| 1 | 0.15522042769493574 | 0.15522042769493574 | 0.4054035371219773 |
| 2 | 0.620881741513388 | 0.620881741513388 | 0.8716141803857071 |
| 3 | 0.6387474552157777 | 0.6387474552157777 | 0.1418603212962489 |