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(sum);
- my %curr = map {$_ => 1} map {m#(\d+)#g} <>;
- for my $blinks (1 .. 75) {
- my %next;
- foreach my $key (keys %curr) {
- if (length($key) % 2 == 0) {
- my $lhs = int substr( $key, 0, length($key) / 2 );
- my $rhs = int substr( $key, length($key) / 2 );
- $next{$lhs} += $curr{$key};
- $next{$rhs} += $curr{$key};
- } else {
- $next{$key * 2024 + ($key == 0)} += $curr{$key};
- }
- }
- %curr = %next;
- say "Part 1: ", sum values %curr if ($blinks == 25);
- }
- say "Part 2: ", sum values %curr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement