day2
parent
bdd8ade7e3
commit
d2eb099d7a
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||
|
||||
|
|
@ -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