This commit is contained in:
Yanick Champoux 2017-12-11 12:13:51 -05:00
parent f6240e130f
commit f5996b47cd
3 changed files with 76 additions and 0 deletions

25
2015/17/1.pl Normal file
View File

@ -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);
}

31
2015/17/2.pl Normal file
View File

@ -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);
}

20
2015/17/input.txt Normal file
View File

@ -0,0 +1,20 @@
33
14
18
20
45
35
16
35
1
13
18
13
50
44
48
6
24
41
30
42