add Day6
This commit is contained in:
parent
45fca03de9
commit
22c4b2b05c
40
Day6/Reproduction.ts
Normal file
40
Day6/Reproduction.ts
Normal 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
1
Day6/input.txt
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user