18 lines
469 B
PHP
18 lines
469 B
PHP
|
<?php
|
||
|
|
||
|
$rucksacks = explode("\n", file_get_contents('./input.txt'));
|
||
|
|
||
|
$lettersToNumbers = array_merge(range('a', 'z'), range('A', 'Z'));
|
||
|
|
||
|
$groups = array_chunk($rucksacks, 3);
|
||
|
|
||
|
echo array_sum(
|
||
|
array_map(
|
||
|
static function($rucksacks) use ($lettersToNumbers) {
|
||
|
[$f, $s, $t] = array_map('str_split', $rucksacks);
|
||
|
return array_search(current(array_intersect($f, $s, $t)), $lettersToNumbers, true) + 1;
|
||
|
},
|
||
|
$groups
|
||
|
)
|
||
|
);
|