AoC day 6, part 1. Fairly straightforward once you realize that all that stuff about aligned columns is irrelevant and you can just treat each line as a list of space-separated tokens. Props to List::Util for including a
transpose function, even if it is named
zip.
use v5.36;<br>use List::Util qw(sum0 product zip);<br><br>my %fn = (<br> '+' => \&sum0,<br> '*' => \&product,<br>);<br><br>my @input = zip map [split], readline;<br><br>my $sum = 0;<br>for my $col (@input) {<br> my $op = pop @$col;<br> $sum += $fn{$op}(@$col);<br>}<br><br>say $sum;<br>
#
AdventOfCode #
perl
Füsilier Breitlinger
in reply to Füsilier Breitlinger • • •Sensitive content
#AdventOfCode #perl
fuzzix
in reply to Füsilier Breitlinger • • •Sensitive content
Very nice - I like the use of zip in part 1.
Ended up using the operator line as a key for column sizes in part 2 ... and I overdid things last night, so I guess this is the sort of code I write when I can only see comfortably out one eye.
gist.github.com/jbarrett/ab488…
Advent of Code day 6
Gist