Browse Source

Day 13 Part 1

master
Graeme Dyas 4 months ago
parent
commit
48ac2ffd29
  1. 36
      Day 13/Part_1.php
  2. 0
      Day 13/Part_2.php
  3. 1
      README.md

36
Day 13/Part_1.php

@ -0,0 +1,36 @@
<?php
$in = file("input.txt", 2);
$time = (int)$in[0];
$range = explode(",", $in[1]);
$ans = array();
foreach ($range as $rk => $r) {
if ($r == "x") {
unset($range[$rk]);
}
}
function listtimes($bus,$time)
{
$x = 0;
$a = array();
do {
if ($x % $bus == 0) {
array_push($a,$x);
}
$x++;
} while ($time + $bus > $x);
return end($a);
}
foreach ($range as $r) {
array_push($ans,array((int)$r,listtimes($r,$time) - $time));
}
function sortByOrder($a, $b) {
return $a[1] - $b[1];
}
usort($ans, 'sortByOrder');
echo $ans[0][0] * $ans[0][1];

0
Day 13/Part_2.php

1
README.md

@ -13,3 +13,4 @@
|10|:heavy_check_mark:|:heavy_check_mark:|
|11|:heavy_check_mark:|:heavy_check_mark:|
|12|:heavy_check_mark:|:heavy_check_mark:|
|13|:heavy_check_mark:|:x:|
Loading…
Cancel
Save