21 lines
514 B
PHP
21 lines
514 B
PHP
<?php
|
|
|
|
$groups = explode("\n\n", file_get_contents('input.txt'));
|
|
|
|
$yesses = 0;
|
|
|
|
foreach ($groups as $group) {
|
|
$persons = explode("\n", $group);
|
|
if (count($persons) === 1) {
|
|
$yesses += strlen(current(array_unique($persons)));
|
|
} else {
|
|
$persons_letters = array_map(static function($person) {
|
|
return array_unique(str_split($person));
|
|
}, $persons);
|
|
|
|
$intersect = array_intersect(...$persons_letters);
|
|
$yesses += count($intersect);
|
|
}
|
|
}
|
|
|
|
echo $yesses; |