]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/29.pl
The rest of Year 2016
[aoc.git] / 2016 / 29.pl
diff --git a/2016/29.pl b/2016/29.pl
new file mode 100755 (executable)
index 0000000..4e1fff5
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my @positions;
+my @npos;
+while (<>) {
+       my ($disc, $pos, $start) = /Disc #(\d+) has (\d+) p.* position (\d+)/;
+       $disc--;
+       $positions[$disc] = $start;
+       $npos[$disc] = $pos;
+}
+
+my $t = -1;
+TIME:
+while (1) {
+       $t++;
+       for my $d (0 .. $#positions) {
+               next TIME if ($positions[$d] + $t + 1 + $d) % $npos[$d];
+       }
+       say "$t";
+       last;
+}
+