This commit is contained in:
Jonas 2023-06-07 16:32:15 +02:00
parent 45fca03de9
commit 22c4b2b05c
2 changed files with 41 additions and 0 deletions

40
Day6/Reproduction.ts Normal file
View File

@ -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());

1
Day6/input.txt Normal file
View File

@ -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