🚧 Commence le jour 10

This commit is contained in:
Clément 2020-12-11 12:17:57 +01:00
parent cc8b9b54f2
commit fab0464298

29
day_10/part_1.php Normal file
View File

@ -0,0 +1,29 @@
<?php
$numbers = array_map('intval', explode("\n", file_get_contents('input.txt')));
sort($numbers);
$difference_of_1 = 0;
$difference_of_3 = 0;
$current_jolt = 0;
while($current_jolt < max($numbers)) {
if (in_array($current_jolt + 1, $numbers, true)) {
$current_jolt++;
$difference_of_1++;
continue;
}
if (in_array($current_jolt + 3, $numbers, true)) {
$current_jolt += 3;
$difference_of_3++;
continue;
}
}
// your device's built-in adapter is always 3 higher than the highest adapter
$difference_of_3++;
$current_jolt += 3;
echo $difference_of_1 * $difference_of_3;