r/backtickbot • u/backtickbot • Dec 06 '20
https://np.reddit.com/r/adventofcode/comments/k7ndux/2020_day_06_solutions/geto6y5/
It is my understanding that weekend puzzles should be more time consuming? 🤔
Php solution:
<?php
$file = file_get_contents('day6.txt');
$groups = explode("\n\n", $file);
//Part 1
$count = 0;
foreach ($groups as $group) {
$group = array_unique(str_split(str_replace("\n", '', $group))); //doppie quote per forza per rilevare il \n
$count += count($group);
}
echo "Part 1: $count\n";
//Part 2
$count = 0;
foreach ($groups as $group) {
$group = array_map('str_split', explode("\n", $group));
if(count($group)<2){
$count += count($group[0]);
continue;
}
$int = call_user_func_array('array_intersect', $group);
$count += count($int)."\n";
}
echo "Part 2: $count\n";
?>
1
Upvotes