✨ Finit le jour 6
This commit is contained in:
parent
1f389e52aa
commit
46b650a808
12
day_6/part_1.php
Normal file
12
day_6/part_1.php
Normal 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
21
day_6/part_2.php
Normal 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;
|
Loading…
Reference in New Issue
Block a user