Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- use List::Util qw(max);
- my @input = map { m#(\d+)#g } <>;
- my $part1 = 0;
- my %hash;
- foreach my $num (@input) {
- my @window;
- my %tmp;
- my $last = $num % 10;
- for (my $i = 0; $i < 2000; $i++) {
- $num = (($num << 6) ^ $num) & 0xffffff;
- $num = (($num >> 5) ^ $num) & 0xffffff;
- $num = (($num << 11) ^ $num) & 0xffffff;
- push( @window, ($num % 10) - $last );
- $last = $num % 10;
- if ($i >= 3) {
- $tmp{"@window"} //= $last;
- shift @window;
- }
- }
- $part1 += $num;
- $hash{$_} += $tmp{$_} foreach (keys %tmp);
- }
- say "Part 1: $part1";
- say "Part 2: ", max values %hash;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement