]> www.fi.muni.cz Git - aoc2020.git/blob - 30.pl
Task 9 Perl Golf-style
[aoc2020.git] / 30.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 < 30000000) {
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                 if $turn % 1_000_000 == 0;
25         $num = $next;
26 }
27
28
29