advent_of_code_2023/day_1/part_1.php
2023-12-11 14:43:47 +01:00

13 lines
394 B
PHP

<?php
$lines = array_filter(explode("\n", file_get_contents('./input.txt')), fn($line) => !empty($line));
echo array_sum(array_map(
static function($line) {
$numbers = array_values(array_filter(array_map(static fn($letter) => is_numeric($letter) ? $letter : null, str_split($line))));
return (int) sprintf('%s%s', $numbers[0], array_pop($numbers));
},
$lines
));