commit 71d2698f9ff0d33b8a65d46825e2e12ad01802e7
parent 799984e56e279d06e9d184b1c336c49ee8ee823a
Author: finwo <finwo@pm.me>
Date: Wed, 24 Dec 2025 14:40:16 +0100
Completed 2025/01
Diffstat:
2 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/2025/01/example.txt b/2025/01/example.txt
@@ -0,0 +1,10 @@
+L68
+L30
+R48
+L5
+R60
+L55
+L1
+L99
+R14
+L82
diff --git a/2025/01/index.js b/2025/01/index.js
@@ -0,0 +1,61 @@
+#!/usr/bin/env node
+
+const fs = require('node:fs');
+const modulo = 100;
+
+let position = 50;
+let zeroes = 0;
+let passed = 0;
+
+const lines = fs
+ .readFileSync('input', 'utf-8')
+ .split('\r\n').join('\n')
+ .split('\r').join('\n')
+ .split('\n')
+ .map(str => str.trim())
+ .filter(str => str)
+
+const directions = {
+ L: (current, offset) => current - offset,
+ R: (current, offset) => current + offset,
+};
+
+const mod = (n, m) => ((n%m)+m)%m;
+
+console.log(`The dial starts by pointing at ${position}`);
+for(const line of lines) {
+ const direction = directions[line.slice(0,1)];
+ const offset = parseInt(line.slice(1), 10);
+
+ let blockPass = position === 0 ? 1 : 0;
+ position = direction(position, offset);
+
+ let prepassed = passed;
+ process.stdout.write(`The dial is rotated ${line} to point at ${mod(position, modulo)}`);
+
+ while (position >= modulo) {
+ position -= modulo;
+ if (position > 0) passed++;
+ }
+
+ while (position < 0) {
+ position += modulo;
+ if (blockPass-- <= 0) {
+ passed++;
+ }
+ }
+
+ if (position === 0) {
+ zeroes++;
+ }
+
+ if (prepassed != passed) {
+ process.stdout.write(`, it points at zero ${passed - prepassed} times`);
+ }
+
+ process.stdout.write('.\n');
+ // console.log(`The dial is rotated ${line} to point at ${position}.`);
+}
+
+console.log(`Stage one password: ${zeroes}`);
+console.log(`Stage two password: ${zeroes + passed}`);