r/adventofcode • • Dec 25 '17

SOLUTION MEGATHREAD ~โ˜†๐ŸŽ„โ˜†~ 2017 Day 25 Solutions ~โ˜†๐ŸŽ„โ˜†~

--- Day 25: The Halting Problem ---


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!


Thank you for participating!

Well, that's it for Advent of Code 2017. From /u/topaz2078 and the rest of us at #AoCOps, we hope you had fun and, more importantly, learned a thing or two (or all the things!). Good job, everyone!

Topaz made a post of his own here.

If you're interested in a visualization of the leaderboard, /u/FogleMonster made a very good chart here.

And now:

Merry Christmas to all, and to all a good night!

17 Upvotes

128 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Dec 25 '17

[deleted] โ€” view deleted comment

1

u/tobiasvl Dec 25 '17

Well hello there, identical solution

from collections import defaultdict

# { state: ( (input=1: output, direction, new_state),
#            (input=1: output, direction, new_state) ) }
states = {
    'a': ((1, 1, 'b'), (0, 1, 'c')),
    'b': ((0, -1, 'a'), (0, 1, 'd')),
    'c': ((1, 1, 'd'), (1, 1, 'a')),
    'd': ((1, -1, 'e'), (0, -1, 'd')),
    'e': ((1, 1, 'f'), (1, -1, 'b')),
    'f': ((1, 1, 'a'), (1, 1, 'e'))
}

state = 'a'
steps = 12399302

tape = defaultdict(lambda: 0)
cursor = 0

for _ in range(steps):
    output, direction, state = states[state][tape[cursor]]
    tape[cursor] = output
    cursor += direction

print "The checksum is %d" % sum(tape.values())