day3
This commit is contained in:
parent
115e014fe1
commit
09768918b2
22
2015/03/houses.pl
Normal file
22
2015/03/houses.pl
Normal file
@ -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;
|
23
2015/03/houses2.pl
Normal file
23
2015/03/houses2.pl
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user