Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function part1(str) {
let numbers = str.split("\n").map(num => parseInt(num));
let count = 0;
let nextIndex = 0;
let mazeSize = numbers.length;
while (nextIndex < mazeSize) {
count++;
const currentIndex = nextIndex;
nextIndex = numbers[currentIndex] + currentIndex;
numbers[currentIndex] = numbers[currentIndex] + 1;
}
return count;
}
function part2(str) {
let numbers = str.split("\n").map(num => parseInt(num));
let count = 0;
let nextIndex = 0;
let mazeSize = numbers.length;
while (nextIndex < mazeSize) {
count++;
const currentIndex = nextIndex;
nextIndex = numbers[currentIndex] + currentIndex;
numbers[currentIndex] =
numbers[currentIndex] + (numbers[currentIndex] >= 3 ? -1 : 1);
}
return count;
}
const input = require("fs").readFileSync("day5-input.txt", "UTF-8");
console.log("Part1:", part1(input));
console.log("Part2:", part2(input));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.