AoC Day 6 – Custom Customs

This is a solution to Advent of Code 2020 day 6, written in Raku.

https://adventofcode.com/2020/day/6

Part One

For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?

For each group, we can use a Bag to collect answers and the number of Bag keys will the number of questions that have received at least one "yes" answer.

Raku

my $input = slurp '6-input.txt';

my @groups = $input.split("\n\n");

say [+] @groups.map(*.comb(/\w/).Bag.keys.elems)
6416

Part Two

For each group, count the number of questions to which everyone answered "yes". What is the sum of those counts?

In part two we can modify the Bag approach and count the number of entries that have a value equal to the number of people in the group.

Raku

  my $input = slurp '6-input.txt';

  my @groups = $input.split("\n\n");

  say [+] @groups.map(
      -> $g {
          my @people = $g.lines;
          @people.comb(/\w/).Bag.values.grep(-> $v { $v == @people.elems }).elems
      })
3050
raku 
comments powered by Disqus