day2
This commit is contained in:
parent
14029d26a5
commit
115e014fe1
15
2015/02/wrapping.pl
Normal file
15
2015/02/wrapping.pl
Normal file
@ -0,0 +1,15 @@
|
||||
use 5.20.0;
|
||||
|
||||
use Algorithm::Combinatorics qw( combinations );
|
||||
use List::AllUtils qw/ sum min product /;
|
||||
|
||||
my $total;
|
||||
for(map {[ split 'x' ]} <>) {
|
||||
my $x = [ combinations($_,2) ];
|
||||
my @v = map { product @$_ } combinations( $_, 2 );
|
||||
$total += sum min( @v ), map { 2*$_ } @v;
|
||||
}
|
||||
|
||||
say $total;
|
||||
|
||||
|
12
2015/02/wrapping_2.pl
Normal file
12
2015/02/wrapping_2.pl
Normal file
@ -0,0 +1,12 @@
|
||||
use 5.20.0;
|
||||
|
||||
use Algorithm::Combinatorics qw( combinations );
|
||||
use List::AllUtils qw/ sum min product /;
|
||||
|
||||
my $total;
|
||||
|
||||
say sum
|
||||
map { 2 * ( $_->[0] + $_->[1] ), product @$_ }
|
||||
map {[ sort { $a <=> $b } split 'x' ]} <>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user