#!/usr/local/bin/perl # day 2015-03 use strict; use warnings; use v5.32; @ARGV = "input" unless @ARGV; chomp( my \$input = do { local \$/; <> } ); my @directions = split //, \$input; my %houses; my (\$x, \$y) = (0, 0); \$houses{ \$x, \$y } += 1; # starting house gets a present foreach ( @directions ) { \$y += 1 if \$_ eq '^'; \$x += 1 if \$_ eq '>'; \$y -= 1 if \$_ eq 'v'; \$x -= 1 if \$_ eq '<'; \$houses{ \$x, \$y } += 1; } say "part 1: ", scalar grep { \$_ > 0 } values %houses; # Solution for Part 2 undef %houses; my (\$santa_x, \$santa_y, \$robot_x, \$robot_y) = (0, 0, 0, 0); \$houses{ 0, 0 } = 2; for ( my \$i = 0; \$i < (scalar @directions) - 1; \$i += 2 ) { \$santa_y += 1 if \$directions[ \$i ] eq '^'; \$santa_x += 1 if \$directions[ \$i ] eq '>'; \$santa_y -= 1 if \$directions[ \$i ] eq 'v'; \$santa_x -= 1 if \$directions[ \$i ] eq '<'; \$houses{ \$santa_x, \$santa_y } += 1; \$robot_y += 1 if \$directions[ \$i + 1 ] eq '^'; \$robot_x += 1 if \$directions[ \$i + 1 ] eq '>'; \$robot_y -= 1 if \$directions[ \$i + 1 ] eq 'v'; \$robot_x -= 1 if \$directions[ \$i + 1 ] eq '<'; \$houses{ \$robot_x, \$robot_y } += 1; } say "part 2: ", scalar grep { \$_ > 0 } values %houses;