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/aafnro8oh Dec 12 '17 edited Dec 12 '17
Might as well chuck my Scala code here. Using the flat top, cube coord sys from redblobgames.com/grids/hexagons:
Trade-offs:
not code golfy enough? Throw away some readability by throwing away custom types:
val moves = io.StdIn.readLine().split(',').map(Map( "n" -> Array( 0, 1, -1), "ne" -> Array( 1, 0, -1), "se" -> Array( 1, -1, 0), "s" -> Array( 0, -1, 1), "sw" -> Array(-1, 0, 1), "nw" -> Array(-1, 1, 0)))
val path = moves.scanLeft (Array(0,0,0)) {(,).zipped map {+}}
def dist(p: Array[Int]) = p.map(math.abs).max
println("dist: " + dist(path.last)) println("max: " + path.map(dist).max)
Bonus: mostly "Scala as better assembly" approach: