package Day15; use strict; use warnings; use v5.32; use Exporter qw( import ); our @EXPORT = qw( init_ingredients find_proportions ); sub init_ingredients { my $input = shift; my %ingredients; foreach ( split /\n/, $input ) { my ( $ingredient, $capacity, $durability, $flavor, $texture, $calories ) = m/(\w+): capacity (-?\d+), durability (-?\d+), flavor (-?\d+), texture (-?\d+), calories (-?\d+)/; $ingredients{ $ingredient }{ capacity } = $capacity; $ingredients{ $ingredient }{ durability } = $durability; $ingredients{ $ingredient }{ flavor } = $flavor; $ingredients{ $ingredient }{ texture } = $texture; $ingredients{ $ingredient }{ calories } = $calories; } return \%ingredients; } sub find_proportions { my $total = shift; my @proportions; foreach my $a ( 0 .. $total ) { foreach my $b ( 0 .. $total - $a ) { foreach my $c ( 0 .. $total - $a - $b ) { foreach my $d ( 0 .. $total - $a - $b - $c ) { next unless ( $a + $b + $c + $d == $total ); push @proportions => [ $a, $b, $c, $d ]; } } } } return \@proportions; } 1;