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
View all comments
Show parent comment
1
u/anadhdguy Dec 03 '16
yup, this solution is only for part1.
For the part2, the gap wasn't the biggest problem (as I didn't OR 0x30 like the one in C, so I can just multiply by 16 instead of 10, and then display the result with
.to_s(16)), but rather that it's not a nice rectangle.Basically, I solved this by using the center of the keypad as origin (
7as(0,0)for the 2nd keypad, so it starts at(0,-2)), and checking that it's in the grid withabs(x)+abs(y) < 2.The oneliner for the part2 (not posted) is 192char, i'm not too happy with it, but don't have time to fix it.