advent_of_code_2020/day_6/part_2.php
2020-12-08 16:38:19 +01:00

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;