Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- my @list = map { chomp; split /,/ } <>;
- my @hash;
- $hash[29999999] = undef;
- foreach my $t (0 .. $#list - 1) {
- $hash[ $list[$t] ] = $t + 1;
- }
- my ($next, $curr) = (int($list[-1]), 0);
- foreach my $t ($#list + 1 .. 29999999) {
- $curr = $next;
- $next = (defined $hash[$curr]) ? $t - $hash[$curr] : 0;
- $hash[$curr] = $t;
- }
- print "$next\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement