From 3a3d8dbe38b49b384e072a21489ca471804ee407 Mon Sep 17 00:00:00 2001
From: Bill Rossi <bassguitarbill@gmail.com>
Date: Tue, 19 Dec 2023 16:25:13 -0500
Subject: [PATCH] JS (ez)

---
 js/2015/1/problem.js | 22 ++++++++++++++++++++++
 js/bin/run           |  6 ++++++
 2 files changed, 28 insertions(+)
 create mode 100644 js/2015/1/problem.js
 create mode 100755 js/bin/run

diff --git a/js/2015/1/problem.js b/js/2015/1/problem.js
new file mode 100644
index 0000000..9cf8c35
--- /dev/null
+++ b/js/2015/1/problem.js
@@ -0,0 +1,22 @@
+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}`);
+});
diff --git a/js/bin/run b/js/bin/run
new file mode 100755
index 0000000..540bfb0
--- /dev/null
+++ b/js/bin/run
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+year=$1
+day=$2
+
+time node $year/$day/problem.js