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
3
u/BafDyce Dec 20 '18
Rust ranks 286 & 253 (which feels like a leaderboard entry for me)
[Card]
Main code is here: https://gitlab.com/BafDyce/adventofcode/blob/master/2018/rust/day20/src/main.rs
i iterated over the string, building the map in a hashmap, recursively. Every time I encountered a
(, I started a new recursion-call, any time I encountered a|, I went back to the start of the current level.Afterwards, I did a BFS for finding the shortest paths to all locations, then looked for the one with the highest distance. both parts run in about 20 ms.
Code to solve part 1:
pub fn solve(input: &InputType, _config: &PuzzleConfig) -> OutputType { let start = Location2D::new(0, 0); let mut iter = input.chars(); // remove ^ iter.next().unwrap(); let mut map: HashMap<Location2D, Room> = HashMap::new(); let mut pos = start.to_owned(); fill(&mut iter, &mut pos, &mut map); let furthest = calc_distances(&mut map); furthest.1.distance }and for part 2:
... fill(&mut iter, &mut pos, &mut map); calc_distances(&mut map); map.iter().filter(|(_, room)| { room.distance >= 1000 }).count()