X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc2020.git;a=blobdiff_plain;f=25.pl;fp=25.pl;h=60b72ca25f501396b397f8e283338c8c32ac5371;hp=0000000000000000000000000000000000000000;hb=b957ac325434a1623becbe1850127821a94c38fe;hpb=bd88b6ce6b17f682d28d427209a0795a89c98fc6 diff --git a/25.pl b/25.pl new file mode 100755 index 0000000..60b72ca --- /dev/null +++ b/25.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl -w + +use strict; + +my $timestamp = <>; +my @buses = grep { /\d+/ } split /,/, <>; + +my ($min_del, $min_bus); +for my $bus (@buses) { + my $delay = $bus*(1+int(($timestamp-1)/$bus))-$timestamp; + print "Bus $bus delay $delay\n"; + if (!defined $min_del || $min_del > $delay) { + $min_bus = $bus; + $min_del = $delay; + } +} + +print "$min_bus * $min_del = ", $min_bus * $min_del, "\n"; +