From d9a6efe3c6ecb3f62d1d720e115b52fdfaa453ff Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Mon, 12 Jan 2026 15:21:15 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Finit=20le=206e=20jours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day_6/part_1.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 day_6/part_1.php diff --git a/day_6/part_1.php b/day_6/part_1.php new file mode 100644 index 0000000..d3fc564 --- /dev/null +++ b/day_6/part_1.php @@ -0,0 +1,35 @@ + array_filter(explode(' ', $row)), explode("\n", file_get_contents('./input.txt'))); + +$array = matrix_rotate_clockwise($array); + +$sums = []; +foreach ($array as $row) { + $operation = array_shift($row); + if ($operation == '+') { + $data = array_sum($row); + } + if ($operation == '*') { + $data = array_reduce($row, function($carry, $item) { + $carry *= $item; + return $carry; + }, 1); + } + + $sums[] = $data; + print_message(sprintf('%s = %s', implode($operation, $row), $data)); +} + +print_message(array_sum($sums)); + +function matrix_rotate_clockwise($matrix) +{ + array_unshift($matrix, null); + $matrix = call_user_func_array('array_map', $matrix); + $matrix = array_map('array_reverse', $matrix); + + return $matrix; +} \ No newline at end of file