Browse Source

Finit le jour 6

main
Clément 11 months ago
parent
commit
46b650a808
  1. 12
      day_6/part_1.php
  2. 21
      day_6/part_2.php

12
day_6/part_1.php

@ -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

@ -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…
Cancel
Save