]> www.fi.muni.cz Git - aoc.git/blob - 2015/28.pl
Day 25: examining the input
[aoc.git] / 2015 / 28.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4 use strict;
5
6 my (%speed, %time, %resttime);
7 my %state;
8 my %dist;
9 my %score;
10
11 while (<>) {
12         my ($name, $sp, $t, $r) = /(\w+) can fly (\d+) .* for (\d+) .*rest for (\d+) /;
13         $speed{$name} = $sp;
14         $time{$name} = $t;
15         $resttime{$name} = $r;
16
17         $state{$name} = $t;
18         $score{$name} = 0;
19 };
20
21
22 my $time = 2503;
23
24 for (1 .. $time) {
25         my $max;
26         for my $n (keys %speed) {
27                 $dist{$n} += $speed{$n} if $state{$n} > 0;
28                 $state{$n} = $time{$n} if --$state{$n} <= -$resttime{$n};
29                 $max = $dist{$n} if !$max || $max < $dist{$n};
30         }
31
32         for my $n (keys %speed) {
33                 $score{$n}++ if $dist{$n} == $max;
34         }
35 }
36
37 my $maxscore;
38 for my $n (keys %speed) {
39         $maxscore = $score{$n} if !$maxscore || $score{$n} > $maxscore;
40 }
41
42 say $maxscore;
43
44