From 8223e8209755dd9c2f8a2053d8ea8f9ef9b5f659 Mon Sep 17 00:00:00 2001 From: Eric Wagoner Date: Mon, 1 Dec 2025 11:08:54 -0500 Subject: [PATCH] Day one, part one --- 01/code.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/01/code.js b/01/code.js index 83a61e0..67ca4f7 100644 --- a/01/code.js +++ b/01/code.js @@ -1,22 +1,35 @@ import { readFileSync } from 'node:fs'; -const inputArray = readFileSync('sample.txt').toString().split("\n"); -// const inputArray = fs.readFileSync('input.txt').toString().split("\n"); +// const inputArray = readFileSync('sample.txt').toString().split("\n"); +const inputArray = readFileSync('input.txt').toString().split("\n"); // Part One -for (i in inputArray) { - const contents = inputArray[i].split(" "); +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(); +console.log(zeroCount); // Part Two -for (i in inputArray) { - const contents = inputArray[i].split(" "); +for (const element of inputArray) { }