Two more stars in PHP!

This commit is contained in:
Steph 2022-12-01 21:02:00 +01:00
parent 9b92330123
commit be61888c85
3 changed files with 1056 additions and 0 deletions

29
2020/9/XMAS.php Executable file
View File

@ -0,0 +1,29 @@
#!/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";
?>

27
2020/9/XMASpt2.php Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
$lines = explode("\n", file_get_contents("input"));
$number = 248131121;
$sum = 0;
$start = 0;
for($i=0; $i<count($lines); $i++) {
$sum += intval($lines[$i]);
while($sum > $number)
$sum -= $lines[$start++];
if($sum === $number)
break;
}
$subset = array_slice($lines, $start, $i - $start);
sort($subset);
echo "Range starts on $start and ends on $i.\n";
echo "Lowest {$subset[0]} and highest " . array_pop($subset) . "\n";
echo "(you can sum them yourself)\n";
?>

1000
2020/9/input Normal file

File diff suppressed because it is too large Load Diff