summaryrefslogtreecommitdiffstats
path: root/2020/day6/group_declaration.pl
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:38:11 +0300
committerYigit Sever2021-12-13 10:38:11 +0300
commit74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch)
treee27db4cd0873c81a53d32277446d926d176304e0 /2020/day6/group_declaration.pl
parent3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff)
parentac8125750abed263619da4cc6d653bb5ab76f007 (diff)
downloadaoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day6/group_declaration.pl')
-rw-r--r--2020/day6/group_declaration.pl32
1 files changed, 32 insertions, 0 deletions
diff --git a/2020/day6/group_declaration.pl b/2020/day6/group_declaration.pl
new file mode 100644
index 0000000..6370e2f
--- /dev/null
+++ b/2020/day6/group_declaration.pl
@@ -0,0 +1,32 @@
1use strict;
2use warnings;
3use Smart::Comments;
4use DDP;
5
6my $batch;
7{
8 local $/;
9 open my $fh, '<', "input" or die "no input present, $!";
10 $batch = <$fh>;
11}
12
13my $all_yeses = 0;
14
15while ($batch =~ m/((?:[^\n][\n]?)+)/gm ) {
16 my $group_answers = $1;
17
18 # count the newlines = number of people
19 my $peeps = $1 =~ tr/\n//;
20
21 chomp $group_answers;
22
23 my %counts;
24 while ($group_answers =~ m/^(\w+)$/mg) {
25 my $person_answers = $1;
26 ++$counts{$_} for split(//, $person_answers);
27 }
28
29 $all_yeses += scalar grep { $_ == $peeps } values %counts;
30}
31
32print $all_yeses;