Browse Source

Day 10 Part 2

master
Graeme Dyas 4 months ago
parent
commit
ed9355ef4b
  1. 39
      Day 10/Part_2.php

39
Day 10/Part_2.php

@ -4,4 +4,41 @@ $in = file("input.txt");
foreach ($in as &$inv) {
$inv = (int)trim($inv);
}
}
$ans = array();
//Add Zero for the source
array_push($in,0);
sort($in);
//Add +3 for the source device
array_push($in,end($in) + 3);
$x = 0;
while ($x < count($in) - 1) {
array_push($ans, $in[$x + 1] - $in[$x]);
$x++;
}
$data = implode($ans);
$data = explode("3", $data);
$data = array_filter($data);
$data_final = array();
foreach ($data as $t) {
if (strlen($t) > 1) {
array_push($data_final, strlen($t));
}
}
sort($data_final);
$a = array(
2=>2,
3=>4,
4=>7,
);
foreach ($data_final as &$t) {
$t = $a[$t];
}
echo array_product($data_final). "\n";
Loading…
Cancel
Save