Skip to content

Instantly share code, notes, and snippets.

@mLuby
Created January 3, 2023 00:49
Show Gist options
  • Save mLuby/d184c08c507fa03292c72acb38a146ff to your computer and use it in GitHub Desktop.
Save mLuby/d184c08c507fa03292c72acb38a146ff to your computer and use it in GitHub Desktop.
A GraphViz solution to a D&D reindeer puzzle from HN.

The original riddle posted on HN.

Official solution: Dancer -> Donder -> Comet -> Vixen -> Blitzen -> Dasher -> Rudolph -> Cupid -> Prancer

My solution's demo link

Screen Shot 2023-01-02 at 7 40 36 PM

Solution code:
digraph {
  rankdir=LR;
  -- Vixen should be behind Rudolph, Prancer and Dasher, whilst Vixen should be in front of Dancer and Comet.
  Vixen -> Rudolph;
  Vixen -> Prancer;
  Vixen -> Dasher;
  Dancer -> Vixen;
  Comet -> Vixen;
  -- Dancer should be behind Donder, Blitzen and Rudolph.
  Dancer -> Donder;
  Dancer -> Blizten;
  Dancer -> Rudolph;
  -- Comet should be behind Cupid, Prancer and Rudolph.
  Comet -> Cupid;
  Comet -> Prancer;
  Comet -> Rudolph;
  -- Donder should be behind Comet, Vixen, Dasher, Prancer and Cupid.
  Donder -> Comet;
  Donder -> Vixen;
  Donder -> Dasher;
  Donder -> Prancer;
  Donder -> Cupid;
  -- Cupid should be in front of Comet, Blitzen, Vixen, Dancer and Rudolph.
  Comet -> Cupid;
  Blizten -> Cupid;
  Vixen -> Cupid;
  Dancer -> Cupid;
  Rudolph -> Cupid;
  -- Prancer should be in front of Blitzen, Donder and Cupid.
  Blizten -> Prancer;
  Donder -> Prancer;
  Cupid -> Prancer;
  -- Blitzen should be behind Cupid but in front of Dancer, Vixen and Donder.
  Blizten -> Cupid;
  Dancer -> Blizten;
  Vixen -> Blizten;
  Donder -> Blizten;
  -- Rudolph should be behind Prancer but in front of Dasher, Dancer and Donder.
  Rudolph -> Prancer;
  Dasher -> Rudolph;
  Dancer -> Rudolph;
  Donder -> Rudolph;
  -- Finally, Dasher should be behind Prancer but in front of Blitzen, Dancer and Vixen.
  Dasher -> Prancer;
  Blizten -> Dasher;
  Dancer -> Dasher;
  Vixen -> Dasher;
}
@ra-bu
Copy link

ra-bu commented Jan 7, 2023

You could simplify the solution graph by piping it through tred, i.e. do a transitive reduction...

@mLuby
Copy link
Author

mLuby commented Jan 7, 2023

Oh cool, I hadn't heard of tred before, thanks. I didn't run GraphViz locally though—just via the web so while you're right that it'd make the solution simpler, it makes "deployment" (so to speak) more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment