🚧 Commence le jour 13

This commit is contained in:
Clément 2020-12-15 10:18:05 +01:00
parent 3698c4b997
commit eaa41f0afb

24
day_13/part_1.php Normal file
View File

@ -0,0 +1,24 @@
<?php
$input = file_get_contents('input.txt');
[$earliest_timestamp, $buses] = explode("\n", $input);
$earliest_timestamp = (int) $earliest_timestamp;
$buses = array_filter(
array_map(static function ($bus) {
return $bus === 'x' ? null : (int) $bus;
}, explode(',', $buses))
);
$timestamp = $earliest_timestamp;
while (true) {
foreach ($buses as $bus) {
if ($timestamp % $bus === 0) {
echo ($timestamp - $earliest_timestamp) * $bus;
exit;
}
}
$timestamp++;
}