9th day both parts

This commit is contained in:
kplaczek
2021-12-10 20:04:11 +01:00
parent cf26c66fc0
commit 3085753552
3 changed files with 109 additions and 0 deletions

31
09/part1.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$input = array_map('str_split', $input);
$sum = 0;
$lowpoints = 0;
for ($i = 0; $i < count($input); $i++) {
for ($j = 0; $j < count($input[0]); $j++) {
$current = $input[$i][$j];
if (isset($input[$i - 1][$j]) && $input[$i - 1][$j] <= $current) {
continue;
}
if (isset($input[$i][$j - 1]) && $input[$i][$j - 1] <= $current) {
continue;
}
if (isset($input[$i][$j + 1]) && $input[$i][$j + 1] <= $current) {
continue;
}
if (isset($input[$i + 1][$j]) && $input[$i + 1][$j] <= $current) {
continue;
}
$sum += $current + 1;
}
}
echo $sum; //500