✨ Finit le 1er jour
This commit is contained in:
parent
5b3705d3e2
commit
44837f9672
11
day_1/part_1.php
Normal file
11
day_1/part_1.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
|
||||
|
||||
foreach ($numbers as $number) {
|
||||
$number_to_2020 = 2020 - $number;
|
||||
if (in_array($number_to_2020, $numbers, true)) {
|
||||
echo $number_to_2020 * $number;
|
||||
exit;
|
||||
}
|
||||
}
|
22
day_1/part_2.php
Normal file
22
day_1/part_2.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
|
||||
|
||||
foreach ($numbers as $i => $number_1) {
|
||||
foreach ($numbers as $j => $number_2) {
|
||||
if ($j <= $i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($number_1 + $number_2 >= 2020) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$number_to_2020 = 2020 - $number_1 - $number_2;
|
||||
|
||||
if (in_array($number_to_2020, $numbers, true)) {
|
||||
echo $number_to_2020 * $number_1 * $number_2;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user