advent_of_code_2020/day_9/part_2.php

26 lines
531 B
PHP
Raw Permalink Normal View History

2020-12-09 13:06:24 +01:00
<?php
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
$current_index = 0;
//$sum = 127;
$sum = 257342611;
while (true) {
$index = $current_index;
$current_sum = 0;
$used_numbers = [];
while ($current_sum <= $sum) {
if ($sum === $current_sum) {
echo min($used_numbers) + max($used_numbers);
exit;
}
$used_numbers[] = $numbers[$index];
$current_sum = array_sum($used_numbers);
$index++;
}
$current_index++;
}