Browse Source

Day 9 Part 1

master
Graeme Dyas 8 months ago
parent
commit
0e1ab44125
  1. 2
      .gitignore
  2. 0
      Day 8/Part_1.php
  3. 0
      Day 8/Part_2.php
  4. 40
      Day 9/Part_1.php
  5. 0
      Day 9/Part_2.php
  6. 1
      README.md

2
.gitignore

@ -1 +1 @@
*input.txt
*input*.txt

0
Day 8/Part_1.php

0
Day 8/Part_2.php

40
Day 9/Part_1.php

@ -0,0 +1,40 @@
<?php
$in = file("input.txt");
foreach ($in as &$inv) {
$inv = (int)trim($inv);
}
function get_preamble($data, $size)
{
$p = array_slice($data, 0, $size);
return $p;
}
function get_sums($data)
{
$out = array();
foreach ($data as $pk => $pv) {
foreach ($data as $pk2 => $pv2) {
if ($pk !== $pk2) {
array_push($out, $pv + $pv2);
}
}
}
$out = array_unique($out);
sort($out);
return $out;
}
while (true) {
$v = get_preamble($in,25);
$v = get_sums($v);
if (!in_array($in[25],$v)) {
print $in[25];
die();
}
array_shift($in);
}

0
Day 9/Part_2.php

1
README.md

@ -9,3 +9,4 @@
|6|:heavy_check_mark:|:heavy_check_mark:|
|7|:heavy_check_mark:|:x:|
|8|:heavy_check_mark:|:heavy_check_mark:|
|9|:heavy_check_mark:|:x:|
Loading…
Cancel
Save