]> www.fi.muni.cz Git - aoc2020.git/commitdiff
Day 15 - what was that?
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 15 Dec 2020 06:48:31 +0000 (07:48 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Tue, 15 Dec 2020 06:48:31 +0000 (07:48 +0100)
29.pl [new file with mode: 0755]
30.pl [new file with mode: 0755]

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;
+}
+
+
+
diff --git a/30.pl b/30.pl
new file mode 100755 (executable)
index 0000000..838171d
--- /dev/null
+++ b/30.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my @start = map { chomp; $_ } split /,/, <>;
+
+my $turn = 0;
+my %nums;
+my $num;
+
+while ($turn < 30000000) {
+       $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"
+               if $turn % 1_000_000 == 0;
+       $num = $next;
+}
+
+
+