Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $part1 = 0;
- my $part2 = 0;
- while (<>) {
- # convert input to majuscle ordinals
- # Using %4 means that a ε [1,3] and b ε [0,2], so some added shifting needed
- my ($a, $b) = map { ord($_) % 4 } split;
- # LDW is (b - (a-1) + 1) % 3 (+1 to shift to 0-2), move score is b + 1
- $part1 += ($b - $a + 2) % 3 * 3 + $b + 1;
- # LWD is just 3 * b, move score is ((a-1) + b) mod 3, but with residue on [1,3]
- $part2 += ($a + $b + 1) % 3 + 1 + 3 * $b;
- }
- print "Part 1: $part1\n";
- print "Part 2: $part2\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement