Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.16;
- use warnings;
- use List::Util qw(all max product);
- # Number of cubes we want to test for:
- my %want = (red => 12, green => 13, blue => 14);
- my $part1 = 0;
- my $part2 = 0;
- foreach (<>) {
- my ($game, $draws) = m#Game (\d+):(.*)#;
- # Get max seen of each type of cube in this game
- my %max = (red => 0, green => 0, blue => 0);
- foreach (split( /[,;]/, $draws )) {
- my ($num, $colour) = m#(\d+) (\w+)#;
- $max{$colour} = max( $max{$colour}, $num );
- }
- $part1 += $game if (all {$want{$_} >= $max{$_}} keys %want);
- $part2 += product values %max;
- }
- say "Part 1: $part1";
- say "Part 2: $part2";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement