16 lines
455 B
PHP
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
|
|
)
|
|
);
|