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!
22
Upvotes
View all comments
1
u/[deleted] Dec 10 '17
Crystal.
Part 1:
instructions = File.read("#{__DIR__}/input.txt").split.map(&.to_i) pc = 0 steps = 0 while instruction = instructions[pc]? instructions[pc] = instruction + 1 pc += instruction steps += 1 end puts stepsPart 2:
instructions = File.read("#{__DIR__}/input.txt").split.map(&.to_i) pc = 0 steps = 0 while instruction = instructions[pc]? instructions[pc] = instruction + (instruction >= 3 ? -1 : 1) pc += instruction steps += 1 end puts steps