From e45d7cbdc20eea0ce5c7c96e7e6751490bd06767 Mon Sep 17 00:00:00 2001 From: Martijn Kunstman Date: Thu, 7 Dec 2023 20:24:23 +0100 Subject: [PATCH] day5 --- day5/script.js | 71 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/day5/script.js b/day5/script.js index 3b36e44..bf3683e 100644 --- a/day5/script.js +++ b/day5/script.js @@ -1,17 +1,74 @@ let data = []; -//fetch("input.txt") -fetch("input1_test.txt") +let answers = []; +let answer2 = 100000000000000; +fetch("input.txt") +//fetch("input1_test.txt") .then((r) => r.text()) .then((d) => { //console.log(d); - d = d.replaceAll("\r", ""); + d = d.replaceAll("\r", ""); data = d.split("\n\n").map((e) => { - return e = e.split(":")[1]; + return (e = e.split(":")[1]); }); for (let i = 0; i < data.length; i++) { - data[i] = data[i].replace("\n", " ").trim().split("\n").map((e) => { - return e.split(" ").map((e) => { return Number(e) }) - }); + data[i] = data[i] + .replace("\n", " ") + .trim() + .split("\n") + .map((e) => { + return e.split(" ").map((e) => { + return Number(e); + }); + }); } console.log(data); + // + // part 1 + // + for (let i = 0; i < data[0].length; i++) { + for (let j = 0; j < data[0][i].length; j++) { + //console.log("seed:"+data[0][i][j]); + answers.push(procesSeed(data[0][i][j])); + // + } + } + answers.sort((a, b) => { + return a - b; + }); + console.log("answer1:" + answers[0]); + // + // part 2 + // + for (let i = 0; i < data[0].length; i++) { + for (let j = 0; j < data[0][i].length; j += 2) { + // + console.log(j); + // // + for (let k = 0; k < data[0][i][j + 1]; k++) { + if (procesSeed(data[0][i][j] + k)= data[k][l][1] && temp < data[k][l][1] + data[k][l][2]) { + seed = data[k][l][0] - (data[k][l][1] - seed); + break; + } + } + } + return seed; +}