🚧 Commence le jour 10
This commit is contained in:
parent
cc8b9b54f2
commit
fab0464298
29
day_10/part_1.php
Normal file
29
day_10/part_1.php
Normal 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;
|
Loading…
Reference in New Issue
Block a user