adventofcode/2018/02/sol1.pl

29 lines
456 B
Perl

use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
/;
use List::UtilsBy qw/ partition_by /;
use List::AllUtils qw/ pairmap sum product /;
my @items =
map {
+{
pairmap { scalar @$b => $a }
partition_by { $_ }
@$_
}
}
map { [ split '' ] }
<>;
say product
map { scalar @$_ }
map {
my $x = $_;
[ grep { $_->{$x} } @items ]
} 2, 3