9th day both parts
This commit is contained in:
31
09/part1.php
Normal file
31
09/part1.php
Normal 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
|
||||
Reference in New Issue
Block a user