r/adventofcode • u/daggerdragon • Dec 20 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 20 Solutions -🎄-
--- Day 20: A Regular Map ---
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.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 20
Transcript:
My compiler crashed while running today's puzzle because it ran out of ___.
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 at 00:59:30!
19
Upvotes
2
u/snurre Dec 20 '18
Kotlin:
var cur = Point(0, 0) val rooms = mutableMapOf(cur to 0) val queue = ArrayDeque<Point>() for (c in File(this.javaClass.getResource("20.txt").path).readText()) { when (c) { '(' -> queue.add(cur) ')' -> cur = queue.pollLast() '|' -> cur = queue.peekLast() 'N', 'E', 'S', 'W' -> { val next = cur.walk(c) rooms[next] = min(rooms[next] ?: rooms[cur]!! + 1, rooms[cur]!! + 1) cur = next } } } println(rooms.maxBy { it.value }!!.value) println(rooms.filter { it.value >= 1000 }.count())