advent_of_code_2022/day_3/part_1.php
2022-12-06 09:47:09 +01:00

16 lines
455 B
PHP

<?php
$rucksacks = explode("\n", file_get_contents('./input.txt'));
$lettersToNumbers = array_merge(range('a', 'z'), range('A', 'Z'));
echo array_sum(
array_map(
static function($rucksack) use ($lettersToNumbers) {
[$f, $s] = array_map('str_split', str_split($rucksack, strlen($rucksack)/2));
return array_search(current(array_intersect($f, $s)), $lettersToNumbers, true) + 1;
},
$rucksacks
)
);