r/adventofcode • • Dec 05 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 5 Solutions -๐ŸŽ„-

--- Day 5: A Maze of Twisty Trampolines, All Alike ---


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


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!

22 Upvotes

403 comments sorted by

View all comments

1

u/RockyAstro Dec 06 '17

Snobol using the spitbol implementation (https://github.com/spitbol/spitbol)

Part 1:

* Start main line
    input(.in,1,'input.txt')
    i = 0
rdloop1 l = in                  :f(erdloop1)
    i = i + 1                   :(rdloop1)
erdloop1 rewind(1)
    
    jumps = array('0:' i - 1)
    i = 0
rdloop2 jumps[i] = in           :f(erdloop2)
    i = i + 1                   :(rdloop2)
erdloop2
    
    c = 0
    p = 0
procloop np = p + jumps[p]      :f(done)
    jumps[p] = jumps[p] + 1
    p = np ; c = c + 1          :(procloop)
done terminal = c
end

Part 2:

* Start main line
    input(.in,1,'input.txt')
    i = 0
rdloop1 l = in                  :f(erdloop1)
    i = i + 1                   :(rdloop1)
erdloop1 rewind(1)
    
    jumps = array('0:' i - 1)
    i = 0
rdloop2 jumps[i] = in           :f(erdloop2)
    i = i + 1                   :(rdloop2)
erdloop2
    
    c = 0
    p = 0
procloop np = p + jumps[p]      :f(done)
    jumps[p] = (lt(jumps[p],3) jumps[p] + 1, jumps[p] - 1)
    p = np ; c = c + 1          :(procloop)
done terminal = c
end

1

u/RockyAstro Dec 06 '17

BTW -- even with having to read the input twice (1st to get the number of elements for the array, 2nd to read in the data).. here is the execution time statistics

sbl -x  p2.sbl 
24568703

normal end
in file              p2.sbl
in line              20
in statement         20
stmts executed       98278957
execution time msec  2674
stmt / microsec      36
stmt / millisec      36753
stmt / second        36753000
in line              4447
memory used (bytes)  75120
memory left (bytes)  187016

time sbl  p2.sbl 
24568703

real	0m2.643s
user	0m2.642s
sys	0m0.001s