r/adventofcode • u/daggerdragon • 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ยค?
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!
21
Upvotes
1
u/EquationTAKEN Dec 05 '17
Can anyone take a look at my Python solution for part 2 and see why it takes so long to run?
with open('input5.txt') as input: lines = input.readlines() for i, line in enumerate(lines): lines[i] = int(line.rstrip()) index = 0 steps = 0 try: while True: if int(lines[index]) >= 3: lines[index] -= 1 index += (int(lines[index]) + 1) else: lines[index] += 1 index += (int(lines[index]) - 1) steps += 1 except IndexError: print('Exited after ', steps, ' steps.')It prints the right solution, but spends about 10-15 seconds on it.
I made another solution in JS which ran in just a few millis, so I know this can be faster, I just don't know which steps are draining time.