Finit le jour 6

This commit is contained in:
Clément 2020-12-08 16:38:19 +01:00
parent 1f389e52aa
commit 46b650a808
2 changed files with 33 additions and 0 deletions

12
day_6/part_1.php Normal file
View File

@ -0,0 +1,12 @@
<?php
$groups = explode("\n\n", file_get_contents('input.txt'));
$yesses = 0;
foreach ($groups as $group) {
$group_yes = implode('', explode("\n", $group));
$yesses += count(array_unique(str_split($group_yes)));
}
echo $yesses;

21
day_6/part_2.php Normal file
View File

@ -0,0 +1,21 @@
<?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;