From 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 12 Dec 2021 01:24:32 +0300 Subject: 2020, tracking --- 2020/day6/group_declaration.pl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 2020/day6/group_declaration.pl (limited to '2020/day6/group_declaration.pl') 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 @@ +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; -- cgit v1.2.3-70-g09d2