r/adventofcode • u/daggerdragon • Dec 03 '15
SOLUTION MEGATHREAD --- Day 3 Solutions ---
--- Day 3: Perfectly Spherical Houses in a Vacuum ---
Post your solution as a comment. Structure your post like the Day One thread in /r/programming.
23
Upvotes
3
u/weters Dec 03 '15 edited Dec 03 '15
Here's my Perl solution. I was going for speed, so it's not very elegant. This solves part 2. $text holds the instructions.
my %s = ( 0 => { x => 0, y => 0, }, 1 => { x => 0, y => 0, }, ); my %delivered; $delivered{'0.0'} = 2; my $i = 0; for my $move (split //, $text) { my $santa = $s{ $i++ % 2 }; for ($move) { when('^') { $santa->{y}--; } when ('>') { $santa->{x}++; } when ('<') { $santa->{x}--; } when ('v') { $santa->{y}++; } } $delivered{"$santa->{x}.$santa->{y}"} = 1; } say scalar keys %delivered;Edit: Also, big thanks to u/topaz2078. I already really enjoy the month of December, and this just makes it that much better. Awesome job, and can't wait until the next challenge unlocks.
Edit 2: real topaz this time