Browse Source

🚧 Commence le jour 13

main
Clément 10 months ago
parent
commit
eaa41f0afb
  1. 24
      day_13/part_1.php

24
day_13/part_1.php

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