浏览代码

Add common functions file

ApisNecros 1 年之前
父节点
当前提交
2fb6fc173e
共有 1 个文件被更改,包括 18 次插入0 次删除
  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;
+}