aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

sol1.pl (415B) [raw]


      1 #!/usr/bin/env perl
      2 use strict;
      3 use warnings;
      4 
      5 my @groups;
      6 open(my $fh, '<', 'input') or die "$!";
      7 {
      8     local $/;
      9     my $content = <$fh>;
     10     @groups = split("\n\n", $content);
     11 }
     12 
     13 # reduce each group to a bag o words, then uniq, count
     14 my $n;
     15 for my $g (@groups) {
     16     my %yes;
     17     for my $m (split("\n", $g)) {
     18         chomp($m);
     19         $yes{$_} = 1 for split('', $m);
     20     }
     21     $n += keys %yes;
     22 }
     23 print "$n\n";