✨ Finit le jour 8 et le début du 9
This commit is contained in:
31
day_9/part_1.php
Normal file
31
day_9/part_1.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
$grid = array_map(static function ($row) {
|
||||
return str_split($row);
|
||||
}, explode("\n", file_get_contents('./input.txt')));
|
||||
|
||||
$low_points = [];
|
||||
|
||||
foreach ($grid as $i => $row) {
|
||||
foreach ($row as $j => $cell) {
|
||||
$count = 0;
|
||||
if (!array_key_exists($i - 1, $grid) || $grid[$i - 1][$j] > $cell) {
|
||||
$count++;
|
||||
}
|
||||
if (!array_key_exists($i + 1, $grid) || $grid[$i + 1][$j] > $cell) {
|
||||
$count++;
|
||||
}
|
||||
if (!array_key_exists($j - 1, $row) ||$row[$j - 1] > $cell) {
|
||||
$count++;
|
||||
}
|
||||
if (!array_key_exists($j + 1, $row) || $row[$j + 1] > $cell) {
|
||||
$count++;
|
||||
}
|
||||
|
||||
if ($count === 4) {
|
||||
$low_points[] = (int) $cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo array_sum($low_points) + count($low_points);
|
Reference in New Issue
Block a user