29 lines
638 B
PHP
29 lines
638 B
PHP
|
<?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;
|