2016-17
This commit is contained in:
parent
f6240e130f
commit
f5996b47cd
25
2015/17/1.pl
Normal file
25
2015/17/1.pl
Normal 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
31
2015/17/2.pl
Normal 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
20
2015/17/input.txt
Normal 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
|
Loading…
Reference in New Issue
Block a user