From: Jan "Yenya" Kasprzak Date: Tue, 15 Dec 2020 06:48:31 +0000 (+0100) Subject: Day 15 - what was that? X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=eecc1b2e975ad2efc811a0cf640e580a031d53a9;p=aoc2020.git Day 15 - what was that? --- diff --git a/29.pl b/29.pl new file mode 100755 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 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; +} + + +