From eecc1b2e975ad2efc811a0cf640e580a031d53a9 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Tue, 15 Dec 2020 07:48:31 +0100 Subject: [PATCH] Day 15 - what was that? --- 29.pl | 28 ++++++++++++++++++++++++++++ 30.pl | 29 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 29.pl create mode 100755 30.pl 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; +} + + + -- 2.43.0