]> www.fi.muni.cz Git - aoc.git/blob - 2017/11.pl
Day 25: examining the input
[aoc.git] / 2017 / 11.pl
1 #!/usr/bin/perl
2
3 use v5.30;
4 use strict;
5
6 chomp (my @banks = split /\s+/, <>);
7
8 my %seen;
9 my $steps;
10 while (1) {
11         my $key = join(',', @banks);
12         last if $seen{$key};
13         $steps++;
14         my ($max, $maxi);
15         for my $i (0 .. $#banks) {
16                 if ($banks[$i] > $max) {
17                         $max = $banks[$i];
18                         $maxi = $i;
19                 }
20         }
21         $banks[$maxi] = 0;
22         while ($max--) {
23                 $maxi = 0 if ++$maxi > $#banks;
24                 $banks[$maxi]++;
25         }
26 }
27 say $steps;