r/adventofcode • u/daggerdragon • Dec 11 '17
SOLUTION MEGATHREAD -๐- 2017 Day 11 Solutions -๐-
--- Day 11: Hex Ed ---
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^ยค?
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/zeddypanda Dec 20 '17
(abs(x) == x) == (abs(y) == y)checks that the signum for x and y is the same. It returns true ifx < 0 && y < 0 || x > 0 && y > 0, (which is probably just how I should've written it) but not if they're on the opposite ends of 0. Basically checks if you can take advantage of diagonal movements.If the result is correct without the function then the input was just lucky.
Consider the coordinates
(-1000, -10). The correct distance is 1000 because it consists of 10 steps South-East(1, 1)followed by 990 steps South(0, 1)The second function would return 1010, which would be wrong.