generated from eric/adventofcode2023
41 lines
703 B
JavaScript
41 lines
703 B
JavaScript
import { readFileSync } from 'node:fs';
|
|
|
|
// const inputArray = readFileSync('sample.txt').toString().split("\n");
|
|
const inputArray = readFileSync('input.txt').toString().split("\n");
|
|
|
|
// Part One
|
|
|
|
let zeroCount = 0;
|
|
let currentPosition = 50;
|
|
|
|
for (const element of inputArray) {
|
|
const instruction = element;
|
|
const direction = instruction[0];
|
|
const steps = Number.parseInt(instruction.slice(1));
|
|
|
|
if (direction === 'L') {
|
|
currentPosition -= steps;
|
|
} else {
|
|
currentPosition += steps;
|
|
}
|
|
|
|
if (currentPosition === 0 || (currentPosition % 100) === 0) {
|
|
zeroCount++;
|
|
}
|
|
}
|
|
|
|
console.log(zeroCount);
|
|
|
|
|
|
// Part Two
|
|
|
|
for (const element of inputArray) {
|
|
|
|
}
|
|
|
|
|
|
console.log();
|
|
|
|
// functions
|
|
|