]> www.fi.muni.cz Git - aoc2020.git/blobdiff - 29.pl
Day 15 - what was that?
[aoc2020.git] / 29.pl
diff --git a/29.pl b/29.pl
new file mode 100755 (executable)
index 0000000..e99bf39
--- /dev/null
+++ b/29.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my @start = map { chomp; $_ } split /,/, <>;
+
+my $turn = 0;
+my %nums;
+my $num;
+
+while ($turn < 2020) {
+       $turn++;
+       if (@start) {
+               $num = shift @start;
+       }
+       my $next;
+       if (defined $nums{$num}) {
+               $next = $turn - $nums{$num};
+       } else {
+               $next = 0;
+       }
+       $nums{$num} = $turn;
+       print "turn $turn, num=$num\n";
+       $num = $next;
+}
+
+
+