From 49cbce92e9cdeeec70bb5b5e7c3b81e8ae0172f2 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Tue, 12 Dec 2023 10:13:08 +0100 Subject: [PATCH] douplicate rows --- Day11/Part1.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Day11/Part1.js b/Day11/Part1.js index 3a620a8..34f63ee 100644 --- a/Day11/Part1.js +++ b/Day11/Part1.js @@ -1,8 +1,22 @@ import { readFileSync } from "fs"; const t0 = performance.now(); -const input = readFileSync("input.txt").toString(); -console.log(input); +const input = readFileSync("input.txt") + .toString() + .split(/\r*\n/) + .filter((e) => e.length > 0) + .map((e) => e.split("")); + +const expand = (arr) => + arr.reduce( + (a, i) => [ + ...a, + ...(i.some((e) => e !== ".") ? [i] : [i, Array(i.length).fill(".")]), + ], + [] + ); + +console.log(expand(input)); const t1 = performance.now(); console.log(`Runtime: ${t1 - t0}ms`);