summary refs log tree commit diff stats
path: root/2020/day-06/day-06.raku
blob: 24f55f43e19031fd7332362b8fcf13c6c7e07baa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env raku

sub MAIN (
    Int $part where * == 1|2 = 1 #= part to run (1 or 2)
) {
    my $input = slurp "input";
    my @answers = $input.chomp.split("\n\n");
    my $count = 0;

    for @answers -> $answer {
        my %yes;
        my @individual_answers = $answer.split("\n");
        %yes{$_} += 1 for @individual_answers.join.comb;

        if $part == 1 {
            $count += keys %yes;
        } elsif $part == 2 {
            for keys %yes {
                $count += 1 if %yes{$_} eq @individual_answers.elems;
            }
        }
    }
    say "Part $part: ", $count;
}