advent_of_code_2022/day_3/part_1.php

16 lines
455 B
PHP
Raw Permalink Normal View History

2022-12-06 09:47:09 +01:00
<?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
)
);