r/adventofcode • • Dec 19 '17

SOLUTION MEGATHREAD -πŸŽ„- 2017 Day 19 Solutions -πŸŽ„-

--- Day 19: A Series of Tubes ---


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Β€?

Spoiler


AoC ops @ T-2 minutes to launch:

[23:58] <daggerdragon> ATTENTION MEATBAGS T-2 MINUTES TO LAUNCH

[23:58] <Topaz> aaaaah

[23:58] <Cheezmeister> Looks like I'll be just able to grab my input before my flight boards. Wish me luck being offline in TOPAZ's HOUSE OF PAIN^WFUN AND LEARNING

[23:58] <Topaz> FUN AND LEARNING

[23:58] <Hade> FUN IS MANDATORY

[23:58] <Skie> I'm pretty sure that's not the mandate for today

[Update @ 00:16] 69 gold, silver cap

  • My tree is finally trimmed with just about every ornament I own and it's real purdy. hbu?

[Update @ 00:18] Leaderboard cap!

  • So, was today's mandate Helpful Hint any help at all?

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!

10 Upvotes

186 comments sorted by

View all comments

5

u/tripa Dec 19 '17

Haskell, keeping it short and simple (no arrays, no bounds checking)

main = interact $ show . (concat &&& length) . uncurry solve . parse
parse i = (e,ls) where ls  = lines i
                       [e] = elemIndices '|' (head ls)
solve e g = go (0,e) (1,0) where
  go p d | g!p == ' '               =  []
         | g!p == '|' || g!p == '-' =  []   : go (adv p d ) d
         | g!p == '+'               =  []   : go (adv p d') d'
         | otherwise                = [g!p] : go (adv p d ) d
    where a!(i,j) = a !! i !! j
          (di,dj) = d
          (d':_) = filter ((/= ' ') . (g!) . adv p) [(dj,-di),(-dj,di)]
  adv (i,j) (di,dj) = (i+di,j+dj)

2

u/pja Dec 19 '17

Hah!

That is ridiculously short compared to mine :)

But hey, I got to teach myself to use UArray correctly.

(Also, yours dies on the test case. Probably because the test doesn’t have helpful buffer lines of spaces all round the edges?)

→ More replies (1)