Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $toss = <>;
- my @buses = map { chomp; split /,/ } <>;
- my %table;
- foreach my $i (0 .. $#buses) {
- next if ($buses[$i] eq 'x');
- $table{ $buses[$i] } = ($buses[$i] - $i) % $buses[$i];
- }
- my @mods = sort { $b <=> $a } keys %table;
- my $jump = shift @mods;
- my $time = $table{$jump};
- while (@mods) {
- my $next = shift @mods;
- while ($time % $next != $table{$next}) {
- $time += $jump;
- }
- $jump *= $next;
- }
- print "Part 2: $time\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement