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