From 115e014fe1e1436e11cc6b3b5318c38e534b4691 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 3 Dec 2017 19:57:32 -0500 Subject: [PATCH] day2 --- 2015/02/wrapping.pl | 15 +++++++++++++++ 2015/02/wrapping_2.pl | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 2015/02/wrapping.pl create mode 100644 2015/02/wrapping_2.pl diff --git a/2015/02/wrapping.pl b/2015/02/wrapping.pl new file mode 100644 index 0000000..ff491a6 --- /dev/null +++ b/2015/02/wrapping.pl @@ -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; + + diff --git a/2015/02/wrapping_2.pl b/2015/02/wrapping_2.pl new file mode 100644 index 0000000..6da0177 --- /dev/null +++ b/2015/02/wrapping_2.pl @@ -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' ]} <>; + +