3rd and 2nd day

This commit is contained in:
kplaczek
2021-12-03 19:25:51 +01:00
parent 1e900f4642
commit 6365d1fef7
9 changed files with 2103 additions and 2017 deletions

18
01/part2.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
/**
*
*/
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$input = array_map('intval', $input);
$increased = 0;
$previousReading = array_sum(array_slice($input, 0, 3));
for ($i = 1; $i < count($input) - 2; $i++) {
$currentReading = array_sum(array_slice($input, $i, 3));
if ($currentReading > $previousReading) {
$increased++;
}
$previousReading = $currentReading;
}
echo $increased; // 1597