Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use List::AllUtils qw(onlyidx sum);
- $| = 1;
- my @list = map { 811589153 * int($_) } <>;
- @list = map { [$_, $list[$_]] } (0 .. $#list);
- foreach (1 .. 10) {
- print ::stderr "Iteration: $_\r";
- for (my $i = 0; $i < @list; $i++) {
- my $idx = onlyidx { $_->[0] == $i } @list;
- my $item = splice( @list, $idx, 1 );
- my $dest = ($idx + $item->[1]) % @list;
- splice( @list, $dest, 0, $item );
- }
- }
- my $zero = onlyidx { $_->[1] == 0 } @list;
- print "\nPart 2: ", sum map { $list[($zero + 1000 * $_) % @list][1] } (1 .. 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement