adventofcode/2020/9/XMAS.php

30 lines
450 B
PHP
Raw Normal View History

2022-12-01 21:02:00 +01:00
#!/usr/bin/env php
<?php
$length = 25;
$lines = explode("\n", file_get_contents("input"));
$valid = 0;
for($i=$length; $i<count($lines); $i++) {
$ival = $lines[$i];
for($x=$i-$length; $x<$i; $x++) {
$xval = $lines[$x];
for($y=$i-$length; $y<$x; $y++) {
$yval = $lines[$y];
if(($xval + $yval) == $ival) {
$valid = $i;
}
}
}
if($valid != $i)
break;
}
echo "First number with bad property is {$lines[$valid + 1]}\n";
?>