day24
This commit is contained in:
parent
75821152c4
commit
8694868b3f
32
2015/24/1.pl
32
2015/24/1.pl
@ -10,11 +10,38 @@ use experimental qw/ signatures postderef /;
|
||||
|
||||
use DDP;
|
||||
|
||||
my @min = ( 1 ) x $goal;
|
||||
my $min = 1E99;
|
||||
aggregate( \@gifts, [shift @gifts], [] );
|
||||
|
||||
aggregate( \@gifts, $goal );
|
||||
|
||||
|
||||
sub aggregate($gifts,$sofar,$next,$done=undef) {
|
||||
sub aggregate($gifts,$goal,@sofar) {
|
||||
use DDP;
|
||||
# p @_;
|
||||
|
||||
return if $goal < 0;
|
||||
|
||||
return if @sofar > @min;
|
||||
return if product(@sofar) > $min;
|
||||
|
||||
if($goal == 0) {
|
||||
@min = @sofar;
|
||||
$min = product(@min);
|
||||
say $min;
|
||||
return;
|
||||
}
|
||||
|
||||
return unless @$gifts;
|
||||
|
||||
my( $i, @gifts) = @$gifts;
|
||||
|
||||
aggregate( \@gifts, $goal - $i, @sofar, $i );
|
||||
aggregate( \@gifts, $goal, @sofar );
|
||||
|
||||
}
|
||||
|
||||
__END__
|
||||
# p @_;
|
||||
my $total = sum $sofar->@*;
|
||||
|
||||
@ -49,7 +76,6 @@ sub aggregate($gifts,$sofar,$next,$done=undef) {
|
||||
|
||||
}
|
||||
|
||||
__END__
|
||||
|
||||
my $min = 1E99;
|
||||
my @poss = possibilities(\@gifts,[]);
|
||||
|
43
2015/24/2.pl
Normal file
43
2015/24/2.pl
Normal file
@ -0,0 +1,43 @@
|
||||
use 5.20.0;
|
||||
|
||||
my @gifts = map { 0+$_} <>;
|
||||
|
||||
use List::AllUtils qw/ sum product min /;
|
||||
|
||||
my $goal = sum(@gifts)/4;
|
||||
|
||||
use experimental qw/ signatures postderef /;
|
||||
|
||||
use DDP;
|
||||
|
||||
my @min = ( 1 ) x $goal;
|
||||
my $min = 1E99;
|
||||
|
||||
aggregate( \@gifts, $goal );
|
||||
|
||||
|
||||
sub aggregate($gifts,$goal,@sofar) {
|
||||
use DDP;
|
||||
# p @_;
|
||||
|
||||
return if $goal < 0;
|
||||
|
||||
return if @sofar > @min;
|
||||
return if product(@sofar) > $min;
|
||||
|
||||
if($goal == 0) {
|
||||
@min = @sofar;
|
||||
$min = product(@min);
|
||||
say $min;
|
||||
return;
|
||||
}
|
||||
|
||||
return unless @$gifts;
|
||||
|
||||
my( $i, @gifts) = @$gifts;
|
||||
|
||||
aggregate( \@gifts, $goal - $i, @sofar, $i );
|
||||
aggregate( \@gifts, $goal, @sofar );
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user