✨ Finit le jour 9
This commit is contained in:
22
day_9/part_1.php
Normal file
22
day_9/part_1.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user