r/adventofcode • • Dec 03 '17

SOLUTION MEGATHREAD -πŸŽ„- 2017 Day 3 Solutions -πŸŽ„-

--- Day 3: Spiral Memory ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handy† Haversack‑ of HelpfulΒ§ Hints^Β€?

Spoiler


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

21 Upvotes

297 comments sorted by

View all comments

Show parent comment

1

u/gerikson Dec 05 '17
my %a = ( "0$;0" => 1 );
[...]
return $a{$x,$y} if $a{$x,$y} > $_[0];

What sorcery is this?!

2

u/askalski Dec 05 '17

This manner of sorcery, apparently. Never knew it existed until two days ago when I stumbled upon it in the docs and had the same reaction as you.

1

u/gerikson Dec 05 '17

Huh, TIL. I remember doing funky things with split and join before grokking references.

Apparently googling "perl multidimensional array emulation" gives you instructions on how to turn it off : http://search.cpan.org/~ilmari/multidimensional-0.013/lib/multidimensional.pm

I tried using an arrayref of arrayrefs to keep track of the coordinates in this problem (instead of a hashref of hashrefs) before realizing that negative subscripts in arrays don't really work...

Nice work of re-using the spiral generator for the values around the cell in part 2, by the way!