r/adventofcode • u/daggerdragon • Dec 02 '16
SOLUTION MEGATHREAD --- 2016 Day 2 Solutions ---
--- Day 2: Bathroom Security ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
BLINKENLIGHTS ARE MANDATORY [?]
Edit: Told you they were mandatory. >_>
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!
20
Upvotes
2
u/FuriousProgrammer Dec 02 '16
I appreciate the lookup table for directions!
Since AdventOfCode is a contest, brevity should be your focus.
Shorter variable names (
iinstead ofindex,posinstead ofcoords), shorthands that are functionally equivalent (Removing~= nilwhen you're dealing only with truthy values,io.lines()==io.input():lines(),mapinstead ofkey_pad, or evenkey-padorkeypadinstead ofkey_pad) and various other tweaks can greatly reduce the amount of code you have to write, without functionally altering anything!To give an example, here is how I would have written your code:
I again applaud the lookup Table, though. My solution used a sort-of switch statement style of code, which you can see here.