r/adventofcode • • Dec 18 '19

SOLUTION MEGATHREAD -🎄- 2019 Day 18 Solutions -🎄-

--- Day 18: Advent of Code-Man: Into the Code-Verse ---

--- Day 18: Many-Worlds Interpretation ---


Post your full code solution using /u/topaz2078's paste or other external repo.

  • Please do NOT post your full code (unless it is very short)
  • If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.

NEW RULE: Include the language(s) you're using.

(thanks, /u/jonathan_paulson!)

(Full posting rules are HERE if you need a refresher).


Reminder: Top-level posts in 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's Poems for Programmers

Click here for full rules

Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.

Day 17's winner #1: TBD, coming soon! "ABABCCBCBA" by /u/DFreiberg!

Oh, this was a hard one... I even tried to temporarily disqualify /u/DFreiberg sorry, mate! if only to give the newcomers a chance but got overruled because this poem meshes so well with today's puzzle. Rest assured, though, Day 17 winner #2 will most likely be one of the newcomers. Which one, though? Tune in during Friday's launch to find out!

A flare now billows outward from the sun's unceasing glare.
It menaces the ship with its immense electric field.
And scaffolding outside the ship, and bots all stationed there
Would fry if they remained in place, the wrong side of the shield.

Your tools: an ASCII camera, a vaccuum bot for dust,
Schematics of the scaffolding. Not much, but try you must.
First, you need your bearings: when the junctions are revealed
You will know just where your vacuum bot can put its wheels and trust.

Map all the turns of scaffolding, and ZIP them tightly sealed,
Then, map compressed, send out the bot, with not a tick to spare.

Enjoy your well-deserved Reddit Silver, and good luck with the rest of the Advent of Code!


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 01:57:26!

20 Upvotes

213 comments sorted by

View all comments

Show parent comment

2

u/Zefick Dec 18 '19

The last optimization works only with the assumption that there is always just one path between any two keys, does it? Seems that all inputs have this property, not taking the central square into account.

1

u/sim642 Dec 18 '19

It actually doesn't. Imagine there is a shortest path "a → c" which happens to contain key "b", so it's really "a → b → c". When at key "a", the optimization simply stops it from considering "a → c" and forces it to only consider "a → b" first. Then the "b → c" part is considered at the next Dijkstra step. No actual path is lost, it just prevents separately handling "a → b → c" and "a → c", which are equivalent in all ways.

Suppose there was another path "a → c" which didn't contain the key "b". It cannot be shorter than the path containing "b". If it's strictly longer, it's never considered because it isn't the shortest. If it is exactly the same length, it's also a useless path because it would take the same number of steps but simply not get "b".