From f5996b47cd79c5838c1bbe8073cc4993464e98ca Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Mon, 11 Dec 2017 12:13:51 -0500 Subject: [PATCH] 2016-17 --- 2015/17/1.pl | 25 +++++++++++++++++++++++++ 2015/17/2.pl | 31 +++++++++++++++++++++++++++++++ 2015/17/input.txt | 20 ++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 2015/17/1.pl create mode 100644 2015/17/2.pl create mode 100644 2015/17/input.txt diff --git a/2015/17/1.pl b/2015/17/1.pl new file mode 100644 index 0000000..0c4ff8d --- /dev/null +++ b/2015/17/1.pl @@ -0,0 +1,25 @@ +use 5.20.0; + +use List::AllUtils qw/ sum min /; + +use experimental 'signatures'; + +my @sizes = <>; +use DDP; p @sizes; + +say number_fitting( 150, sum(@sizes), @sizes ); + +sub number_fitting( $left, $max, @sizes ) { + return 0 if $max < $left; + + return 0 if $left and not @sizes; + + return 1 unless $left; + + my $this = shift @sizes; + + return sum map { + number_fitting( $left - $_ * $this, $max - $this, @sizes ); + } 0..min 1, ($left / $this); + +} diff --git a/2015/17/2.pl b/2015/17/2.pl new file mode 100644 index 0000000..5c5d3f2 --- /dev/null +++ b/2015/17/2.pl @@ -0,0 +1,31 @@ +use 5.20.0; + +use List::AllUtils qw/ sum min first /; + +use experimental 'signatures'; + +my @sizes = <>; +use DDP; p @sizes; + +say number_fitting( 150, sum(@sizes), 0, @sizes ); + +my @nbr_containers; + +say first { $_ } @nbr_containers; + + + +sub number_fitting( $left, $max, $nbr, @sizes ) { + return 0 if $max < $left; + + return 0 if $left and not @sizes; + + return $nbr_containers[$nbr]++ unless $left; + + my $this = shift @sizes; + + return sum map { + number_fitting( $left - $_ * $this, $max - $this, $nbr + $_, @sizes ); + } 0..min 1, ($left / $this); + +} diff --git a/2015/17/input.txt b/2015/17/input.txt new file mode 100644 index 0000000..6b25a72 --- /dev/null +++ b/2015/17/input.txt @@ -0,0 +1,20 @@ +33 +14 +18 +20 +45 +35 +16 +35 +1 +13 +18 +13 +50 +44 +48 +6 +24 +41 +30 +42