From 22c4b2b05cc70aff5402a66b0f0e361b4dd3cac1 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 7 Jun 2023 16:32:15 +0200 Subject: [PATCH] add Day6 --- Day6/Reproduction.ts | 40 ++++++++++++++++++++++++++++++++++++++++ Day6/input.txt | 1 + 2 files changed, 41 insertions(+) create mode 100644 Day6/Reproduction.ts create mode 100644 Day6/input.txt diff --git a/Day6/Reproduction.ts b/Day6/Reproduction.ts new file mode 100644 index 0000000..871bf75 --- /dev/null +++ b/Day6/Reproduction.ts @@ -0,0 +1,40 @@ +import { readLines } from "https://deno.land/std@0.177.1/io/read_lines.ts"; + +function step(fish: number[]) { + const result = [0,0,0,0,0,0,0,0,0]; + for (let i = 1; i <= 8; i++) { + result[i-1] = fish[i]; + } + result[8] = fish[0]; + result[6] += fish[0]; + return result; +} + +async function simulate(rounds: number) { + const file = await Deno.open("./Day6/input.txt"); + const lines = readLines(file); + let line: string = (await lines.next()).value; + + let fish = [0,0,0,0,0,0,0,0,0] + + for (let s of line.split(",")) { + fish[+s] += 1; + } + for (let i = 0; i < rounds; i++) { + fish = step(fish); + } + return fish.reduce((a,b) => a + b) +} + +async function Part1() { + return simulate(80); +} + +async function Part2() { + return simulate(256); +} + + +console.log("Part1: " + await Part1()); +console.log("Part1: " + await Part2()); + diff --git a/Day6/input.txt b/Day6/input.txt new file mode 100644 index 0000000..149e1e2 --- /dev/null +++ b/Day6/input.txt @@ -0,0 +1 @@ +1,1,1,2,1,1,2,1,1,1,5,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,4,1,1,1,1,3,1,1,3,1,1,1,4,1,5,1,3,1,1,1,1,1,5,1,1,1,1,1,5,5,2,5,1,1,2,1,1,1,1,3,4,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,5,4,1,1,1,1,1,5,1,2,4,1,1,1,1,1,3,3,2,1,1,4,1,1,5,5,1,1,1,1,1,2,5,1,4,1,1,1,1,1,1,2,1,1,5,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,3,1,1,3,1,3,1,4,1,5,4,1,1,2,1,1,5,1,1,1,1,1,5,1,1,1,1,1,1,1,1,1,4,1,1,4,1,1,1,1,1,1,1,5,4,1,2,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,4,1,1,1,2,1,4,1,1,1,1,1,1,1,1,1,4,2,1,2,1,1,4,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,3,2,1,4,1,5,1,1,1,4,5,1,1,1,1,1,1,5,1,1,5,1,2,1,1,2,4,1,1,2,1,5,5,3