advent_of_code_2020/day_9/part_1.php
2020-12-09 13:06:24 +01:00

23 lines
624 B
PHP

<?php
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
$current_index = 0;
$step = 25;
while (true) {
for ($l = count($numbers) - $step; $current_index <= $l; $current_index++) {
$number_to_test = $numbers[$current_index + $step];
$numbers_to_addition = array_slice($numbers, $current_index, $step);
foreach ($numbers_to_addition as $number) {
if (in_array($number_to_test - $number, $numbers_to_addition, true)) {
$current_index++;
break 2;
}
}
echo $number_to_test;
exit;
}
}