aoc2015

Advent of Code 2015 solutions in Perl.
git clone git://git.samirparikh.com/aoc2015
Log | Files | Refs | README

commit d0caed3addb8fa1abc5ba2cc4a41bb07da9abe8e
parent e40379e780201e726da4fa85f1157bc58e280c18
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Tue,  8 Nov 2022 16:07:16 +0000

solve part 2 of day15

Diffstat:
Mday15/day15.pl | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/day15/day15.pl b/day15/day15.pl @@ -12,10 +12,12 @@ use List::Util qw( max ); chomp( my $input = do { local $/; <> } ); my $TOTAL = 100; +my $CALORIES = 500; my %ingredients = %{ init_ingredients ( $input ) }; my @ingredients = sort keys %ingredients; my @proportions = @{ find_proportions( $TOTAL ) }; -my @scores; +my @scores1; +my @scores2; foreach my $proportion ( @proportions ) { # array ref my ( $capacity, $durability, $flavor, $texture, $calories ) = ( 0, 0, 0, 0, 0 ); @@ -37,7 +39,9 @@ foreach my $proportion ( @proportions ) { # array ref $texture = ( $texture < 0 ) ? 0 : $texture; $calories = ( $calories < 0 ) ? 0 : $calories; my $score = $capacity * $durability * $flavor * $texture; - push @scores => $score; + push @scores1 => $score; + push @scores2 => $score if ( $calories == $CALORIES ); } -say "part 1: ", max @scores; +say "part 1: ", max @scores1; +say "part 2: ", max @scores2;