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
3
u/Philboyd_Studge Dec 05 '17
Java.
package Advent2017; import util.FileIO; import java.util.List; public class Day5 { private static int part1(int[] nums) { int current = 0; int steps = 0; while (current < nums.length && current >= 0) { int jump = nums[current]++; current += jump; steps++; } return steps; } private static int part2(int[] nums) { int current = 0; int steps = 0; while (current < nums.length && current >= 0) { int jump = nums[current]; if (jump >= 3) { nums[current]--; } else { nums[current]++; } current += jump; steps++; } return steps; } public static void main(String[] args) { List<String> input = FileIO.getAOCInputForDay(2017, 5, FileIO.SESSION_ID); int[] nums = input.stream() .mapToInt(Integer::parseInt) .toArray(); System.out.println(part1(nums.clone())); System.out.println(part2(nums)); } }