Browse Source

Add common functions file

ApisNecros 1 year ago
parent
commit
2fb6fc173e
1 changed files with 18 additions and 0 deletions
  1. 18 0
      common.ts

+ 18 - 0
common.ts

@@ -0,0 +1,18 @@
+import * as fs from "fs";
+import * as readline from "readline";
+
+export async function LoadInput(dayNumber: number): Promise<string[]> {
+	const contents = [];
+	const stream = fs.createReadStream(`./inputs/${dayNumber}.txt`, "utf8");
+
+	const rl = readline.createInterface({
+		input: stream,
+		crlfDelay: Infinity,
+	});
+
+	for await (const line of rl) {
+		contents.push(line);
+	}
+
+	return contents;
+}