]> www.fi.muni.cz Git - aoc2020.git/blob - 29.pl
Task 9 Perl Golf-style
[aoc2020.git] / 29.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @start = map { chomp; $_ } split /,/, <>;
6
7 my $turn = 0;
8 my %nums;
9 my $num;
10
11 while ($turn < 2020) {
12         $turn++;
13         if (@start) {
14                 $num = shift @start;
15         }
16         my $next;
17         if (defined $nums{$num}) {
18                 $next = $turn - $nums{$num};
19         } else {
20                 $next = 0;
21         }
22         $nums{$num} = $turn;
23         print "turn $turn, num=$num\n";
24         $num = $next;
25 }
26
27
28