Browse Source

Day 6

master
Graeme Dyas 4 months ago
parent
commit
b98e3649ba
  1. 21
      Day 6/Part_1.php
  2. 36
      Day 6/Part_2.php

21
Day 6/Part_1.php

@ -0,0 +1,21 @@
<?php
$in = explode("\n\n",file_get_contents("input.txt"));
$c = 0;
foreach($in as $ink => &$inv) {
trim($inv);
$inv = str_replace("\n","",$inv);
$inv = str_split($inv);
$inv = array_unique($inv);
$c = $c + count($inv);
}
//$c = 0;
// foreach($in as $ink => &$inv) {
// $c = $c + count(array_unique(str_split(str_replace("\n","",trim($inv)))));
// }
echo $c;

36
Day 6/Part_2.php

@ -0,0 +1,36 @@
<?php
$in = explode("\n\n", file_get_contents("input.txt"));
$t = 0;
foreach ($in as $ink => &$inv) {
trim($inv);
$inv = explode("\n", $inv);
foreach ($inv as $inv2k => &$inv2v) {
$inv2v = str_split($inv2v);
}
}
foreach ($in as $group) {
$c = 0;
$size = count($group);
$c2 = array();
foreach ($group as $person) {
foreach ($person as $answer) {
if (!array_key_exists($answer, $c2)) {
$c2[$answer] = 1;
} else {
$c2[$answer]++;
}
}
}
foreach ($c2 as $c22) {
if ($c22 == $size) {
$c++;
}
}
$t = $t + $c;
}
echo $t;
Loading…
Cancel
Save