X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc2020.git;a=blobdiff_plain;f=26.pl;fp=26.pl;h=90d07aeb4fcda5c151dc630627f1499ed8510fa6;hp=0000000000000000000000000000000000000000;hb=b957ac325434a1623becbe1850127821a94c38fe;hpb=bd88b6ce6b17f682d28d427209a0795a89c98fc6 diff --git a/26.pl b/26.pl new file mode 100755 index 0000000..90d07ae --- /dev/null +++ b/26.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl -w + +use strict; + +my $timestamp = <>; +my @buses = split /,/, <>; + +my $mins = 1; +my %bus_time; +my $first = shift @buses; +for my $bus (@buses) { + if ($bus =~ /\d/) { + $bus_time{$bus} = $mins % $bus; + print "Bus $bus at t+$mins ($bus_time{$bus})\n"; + } + $mins++; +} + +@buses = grep /\d/, @buses; + +my $t = $first; +my $add = $first; + +for my $bus (keys %bus_time) { + print "bus $bus at $bus_time{$bus}\n"; + while (1) { + print "t=$t, add=$add\n"; + last if ($t + $bus_time{$bus}) % $bus == 0; + $t += $add; + } + $add *= $bus; +} +print "t=$t\n"; +