✨ Two more stars in PHP!
This commit is contained in:
parent
9b92330123
commit
be61888c85
29
2020/9/XMAS.php
Executable file
29
2020/9/XMAS.php
Executable 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
27
2020/9/XMASpt2.php
Executable 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
1000
2020/9/input
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user