Files
advent_of_code_2021/09/part1.php
2021-12-10 20:04:11 +01:00

32 lines
764 B
PHP

<?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