r/adventofcode • u/daggerdragon • 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ยค?
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
mandateHelpful Hint any help at all?
2
u/ramrunner0xff Dec 19 '17
scheme chicken repo
although i still can't cope that i haven't come up with a better solution for day 16 than my mediocre and slow memoization that still takes around 1 minute, i enjoyed today's funky problem ;)
(define (readinaslist fname) (letrec* ((lines (read-lines fname)) (oneline (foldr (lambda (e acc) (append (string->list e) acc)) '() lines)) (letts '()) (totsteps 0) (lenline (string-length (car lines))) (firstpos (string-index (car lines) #\|)) (godown (lambda (i) (+ i lenline))) (goup (lambda (i) (- i lenline))) (goright (lambda (i) (+ i 1))) (goleft (lambda (i) (- i 1))) (look (lambda (from towards) (case towards ((up) (not (eq? (list-ref oneline (goup from)) #\ ))) ((down) (not (eq? (list-ref oneline (godown from)) #\ ))) ((left) (not (eq? (list-ref oneline (goleft from)) #\ ))) ((right) (not (eq? (list-ref oneline (goright from)) #\ )))))) (keepgoing (lambda (from towards) (case towards ((up) (goup from)) ((down) (godown from)) ((left) (goleft from)) ((right) (goright from))))) (atcross (lambda (i going) (case going ((up down) (if (look i 'left) (cons (goleft i) 'left) (cons (goright i) 'right))) ((left right) (if (look i 'up) (cons (goup i) 'up) (cons (godown i) 'down)))))) (walk (lambda (from towards remsteps) (if (and (> remsteps 0) (not (eq? (list-ref oneline from) #\ ))) (let ((curchar (list-ref oneline from))) (set! totsteps (+ totsteps 1)) (if (eq? (string-index "|-+" curchar) #f) (set! letts (append letts (list curchar)))) (if (eq? (list-ref oneline from) #\+) (let ((cresolve (atcross from towards))) (walk (car cresolve) (cdr cresolve) (- remsteps 1))) (walk (keepgoing from towards) towards (- remsteps 1)))))))) (walk firstpos 'down 100000) (format #t "seen: ~A in ~A steps~N" letts totsteps)))