A straightforward day 1 for a Javascript / NodeJS solution.
Poorly Optimized JS Solution
let position = 50;
let answer1 = 0;
let answer2 = 0;
const sequence = require('fs').readFileSync('input-day1.txt', 'utf-8');
sequence.split('\n').forEach(instruction => {
const turn = instruction.charAt(0);
let distance = parseInt(instruction.slice(1), 10);
while (distance > 0) {
distance -= 1;
if (turn === 'L') {
position -= 1;
} else if (turn === 'R') {
position += 1;
}
if (position >= 100) {
position -= 100;
} else if (position < 0) {
position += 100;
}
if (position === 0) {
answer2 += 1;
}
}
if (position === 0) {
answer1 += 1;
}
});
console.log(`Part 1 Answer: ${answer1}`);
console.log(`Part 2 Answer: ${answer2}`);
Javascript
More bruteforcing! There are probably better ways to do this but I'm happy enough with this lol.
Solution
You can replace the require('fs') on the first line with the input and run it in your browser console as well.