commit 7d94ac6d2ab0efa4014245fe620c1ff549d66596
parent d0caed3addb8fa1abc5ba2cc4a41bb07da9abe8e
Author: Samir Parikh <noreply@samirparikh.com>
Date: Tue, 8 Nov 2022 16:49:25 +0000
solve both parts for day17
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/day17/day17.pl b/day17/day17.pl
@@ -0,0 +1,29 @@
+#!/usr/local/bin/perl
+# day 2015-17
+
+use strict;
+use warnings;
+use v5.32;
+use List::Util qw ( min );
+use Algorithm::Knapsack; # I know, this is cheating
+
+@ARGV = "input" unless @ARGV;
+chomp( my $input = do { local $/; <> } );
+
+my @containers = split /\n/, $input;
+my $LITERS = 150;
+my @num_containers;
+
+my $knapsack = Algorithm::Knapsack->new(
+ capacity => $LITERS,
+ weights => \@containers,
+);
+
+$knapsack->compute();
+
+foreach my $solution ($knapsack->solutions()) {
+ push @num_containers => scalar ( map { $containers[$_] } @{$solution} );
+}
+
+say "part 1: ", scalar $knapsack->solutions();
+say "part 2: ", scalar grep { $_ == min @num_containers } @num_containers;
diff --git a/day17/input b/day17/input
@@ -0,0 +1,20 @@
+43
+3
+4
+10
+21
+44
+4
+6
+47
+41
+34
+17
+17
+44
+36
+31
+46
+9
+27
+38