aoc_omni/js/2015/1/problem.js
2023-12-19 16:25:13 -05:00

23 lines
519 B
JavaScript

const fs = require('node:fs');
fs.readFile('../data/2015/1/input.txt', (err, input) => {
let floor = 0;
for (c of input) {
const paren = String.fromCharCode(c);
if (paren == '(') floor++;
else if (paren == ')') floor--;
}
console.log(`Part 1: ${floor}`);
floor = 0;
let steps = 0;
for (c of input) {
const paren = String.fromCharCode(c);
if (paren == '(') floor++;
else if (paren == ')') floor--;
steps++;
if (floor < 0) break;
}
console.log(`Part 2: ${steps}`);
});