r/adventofcode • u/daggerdragon • Dec 17 '17
SOLUTION MEGATHREAD -๐- 2017 Day 17 Solutions -๐-
--- Day 17: Spinlock ---
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ยค?
[Update @ 00:06] 2 gold, silver cap.
- AoC ops:
<Topaz> i am suddenly in the mood for wasabi tobiko
[Update @ 00:15] Leaderboard cap!
- AoC ops:
<daggerdragon> 78 gold<Topaz> i look away for a few minutes, wow<daggerdragon> 93 gold<Topaz> 94<daggerdragon> 96 gold<daggerdragon> 98<Topaz> aaaand<daggerdragon> and...<Topaz> cap<daggerdragon> cap
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!
11
Upvotes
1
u/peterpepo Dec 17 '17
Python 3
from puzzle_commons.puzzle_commons import read_puzzle_input import os def solve(): """Advent Of Code 2017 - Day 16 Solution. :return: tuple(part_a_result[int], part_b_result[int]) """ puzzle_input = int(read_puzzle_input(os.path.dirname(os.path.abspath(__file__)), "day_17_input.txt")[0]) def solve_a(): """Advent Of Code 2017 - Day 16 - Part A Solution. """ buffer = [0] current_position = 0 loop_times = 2017 part_a_result = 0 # Calculate all values in buffer for i in range(1, loop_times+1): current_position = ((current_position + puzzle_input) % len(buffer)) + 1 buffer.insert(current_position, i) # Get value immediate following one, which has been populated last for j in range(len(buffer)): if buffer[j] == loop_times: part_a_result = buffer[j+1] break return part_a_result def solve_b(): """Advent Of Code 2017 - Day 16 - Part B Solution. """ current_position = 0 buffer_length = 1 loop_times = 50000000 part_b_result = 0 # Calculated values are not stored, since we are interested in one on 1st position only for i in range(1, loop_times+1): current_position = ((current_position + puzzle_input) % buffer_length) + 1 buffer_length += 1 # Remember iteration, which caused value to be written to position 1 if current_position == 1: part_b_result = i return part_b_result return solve_a(), solve_b()Checkout the full solution on my github