summaryrefslogtreecommitdiffstats
path: root/2020/day6/group_declaration.pl
blob: 6370e2f8905b9f98049140d97a240a05fbc95a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use strict;
use warnings;
use Smart::Comments;
use DDP;

my $batch;
{
    local $/;
    open my $fh, '<', "input" or die "no input present, $!";
    $batch = <$fh>;
}

my $all_yeses = 0;

while ($batch =~ m/((?:[^\n][\n]?)+)/gm ) {
    my $group_answers = $1;

    # count the newlines = number of people
    my $peeps = $1 =~ tr/\n//;

    chomp $group_answers;

    my %counts;
    while ($group_answers =~ m/^(\w+)$/mg) {
        my $person_answers = $1;
        ++$counts{$_} for split(//, $person_answers);
    }

    $all_yeses += scalar grep { $_ == $peeps } values %counts;
}

print $all_yeses;