Browse Source

🚧 Commence le jour 10

main
Clément 11 months ago
parent
commit
fab0464298
  1. 29
      day_10/part_1.php

29
day_10/part_1.php

@ -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;
Loading…
Cancel
Save