adventofcode/2015/14/2.pl
Yanick Champoux 25281404f1 day14
2017-12-06 12:48:31 -05:00

27 lines
535 B
Perl

use 5.20.0;
use List::AllUtils qw/ max/;
use experimental qw/ postderef /;
use List::UtilsBy qw/ max_by /;
my %reindeer =
map { $_->[0] => [ ($_->[1]) x $_->[2], ( 0 ) x $_->[3] ] }
map { [ /(\S+).*?(\d+).*?(\d+).*?(\d+)/ ] } <>;
use DDP;
p %reindeer;
my %dist;
my %score;
for ( 0..2502 ) {
while( my( $r, $s ) = each %reindeer ) {
$dist{$r} += $reindeer{$r}[ $_ % $reindeer{$r}->@* ]
}
my $max = max values %dist;
$score{$_}++ for grep { $dist{$_} == $max } keys %dist;
}
say max values %score;