diff options
author | Yigit Sever | 2021-12-12 01:24:32 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-12 01:24:32 +0300 |
commit | 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e (patch) | |
tree | d6478c85c0488a1059567ccd2882cb10039c2546 /2020/day6/declaration.pl | |
parent | ae3853b6e8ab02023ccd74baac6dc177b1ee879a (diff) | |
download | aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.gz aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.bz2 aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.zip |
2020, tracking
Diffstat (limited to '2020/day6/declaration.pl')
-rw-r--r-- | 2020/day6/declaration.pl | 30 |
1 files changed, 30 insertions, 0 deletions
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 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use Smart::Comments; | ||
4 | use DDP; | ||
5 | use List::Util 'sum'; | ||
6 | |||
7 | my $batch; | ||
8 | { | ||
9 | local $/; | ||
10 | open my $fh, '<', "input" or die "no input present, $!"; | ||
11 | $batch = <$fh>; | ||
12 | } | ||
13 | |||
14 | my $total_yes = 0; | ||
15 | |||
16 | while ($batch =~ m/((?:[^\n][\n]?)+)/gm ) { | ||
17 | my $group_answers = $1; | ||
18 | chomp $group_answers; | ||
19 | |||
20 | my %counts; | ||
21 | while ($group_answers =~ m/^(\w+)$/mg) { | ||
22 | my $person_answers = $1; | ||
23 | $counts{$_} = 1 for split(//, $person_answers); | ||
24 | } | ||
25 | # p %counts; | ||
26 | |||
27 | $total_yes += sum values %counts | ||
28 | } | ||
29 | |||
30 | print $total_yes; | ||