From 09768918b2319df336935f4bcd904be9f4cd95e9 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 3 Dec 2017 20:28:03 -0500 Subject: [PATCH] day3 --- 2015/03/houses.pl | 22 ++++++++++++++++++++++ 2015/03/houses2.pl | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 2015/03/houses.pl create mode 100644 2015/03/houses2.pl diff --git a/2015/03/houses.pl b/2015/03/houses.pl new file mode 100644 index 0000000..2e76855 --- /dev/null +++ b/2015/03/houses.pl @@ -0,0 +1,22 @@ +use 5.20.0; + +my %directions = ( + 'v' => [ 0, 1 ], + '^' => [ 0, -1 ], + '<' => [ 1, 0 ], + '>' => [ -1, 0 ], +); + +my @last = (0,0); +my @positions = ( + [0,0], + map { + my @this = ( $last[0] + $_->[0], $last[1] + $_->[1] ); + @last = @this; + \@this; + } + map { $directions{$_} } split '', <> ); + +use List::AllUtils qw/ uniq /; +@positions = uniq map { join ':', @$_ } @positions; +say scalar @positions; diff --git a/2015/03/houses2.pl b/2015/03/houses2.pl new file mode 100644 index 0000000..b176a1c --- /dev/null +++ b/2015/03/houses2.pl @@ -0,0 +1,23 @@ +use 5.20.0; + +my %directions = ( + 'v' => [ 0, 1 ], + '^' => [ 0, -1 ], + '<' => [ 1, 0 ], + '>' => [ -1, 0 ], +); + +my @last = ([0,0],[0,0]); +my @positions = ( + [0,0], + map { + my $last = shift @last; + my @this = ( $last->[0] + $_->[0], $last->[1] + $_->[1] ); + push @last, \@this; + \@this; + } + map { $directions{$_} } split '', <> ); + +use List::AllUtils qw/ uniq /; +@positions = uniq map { join ':', @$_ } @positions; +say scalar @positions;