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/declaration.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 2020/day6/declaration.pl (limited to '2020/day6/declaration.pl') diff --git a/2020/day6/declaration.pl b/2020/day6/declaration.pl new file mode 100644 index 0000000..7c87461 --- /dev/null +++ b/2020/day6/declaration.pl @@ -0,0 +1,30 @@ +use strict; +use warnings; +use Smart::Comments; +use DDP; +use List::Util 'sum'; + +my $batch; +{ + local $/; + open my $fh, '<', "input" or die "no input present, $!"; + $batch = <$fh>; +} + +my $total_yes = 0; + +while ($batch =~ m/((?:[^\n][\n]?)+)/gm ) { + my $group_answers = $1; + chomp $group_answers; + + my %counts; + while ($group_answers =~ m/^(\w+)$/mg) { + my $person_answers = $1; + $counts{$_} = 1 for split(//, $person_answers); + } + # p %counts; + + $total_yes += sum values %counts +} + +print $total_yes; -- cgit v1.2.3-70-g09d2