🚧 Commence le jour 13
This commit is contained in:
parent
3698c4b997
commit
eaa41f0afb
24
day_13/part_1.php
Normal file
24
day_13/part_1.php
Normal 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++;
|
||||
}
|
Loading…
Reference in New Issue
Block a user