2021-06
parent
a99feea747
commit
06e380c953
|
@ -0,0 +1 @@
|
|||
2,3,1,3,4,4,1,5,2,3,1,1,4,5,5,3,5,5,4,1,2,1,1,1,1,1,1,4,1,1,1,4,1,3,1,4,1,1,4,1,3,4,5,1,1,5,3,4,3,4,1,5,1,3,1,1,1,3,5,3,2,3,1,5,2,2,1,1,4,1,1,2,2,2,2,3,2,1,2,5,4,1,1,1,5,5,3,1,3,2,2,2,5,1,5,2,4,1,1,3,3,5,2,3,1,2,1,5,1,4,3,5,2,1,5,3,4,4,5,3,1,2,4,3,4,1,3,1,1,2,5,4,3,5,3,2,1,4,1,4,4,2,3,1,1,2,1,1,3,3,3,1,1,2,2,1,1,1,5,1,5,1,4,5,1,5,2,4,3,1,1,3,2,2,1,4,3,1,1,1,3,3,3,4,5,2,3,3,1,3,1,4,1,1,1,2,5,1,4,1,2,4,5,4,1,5,1,5,5,1,5,5,2,5,5,1,4,5,1,1,3,2,5,5,5,4,3,2,5,4,1,1,2,4,4,1,1,1,3,2,1,1,2,1,2,2,3,4,5,4,1,4,5,1,1,5,5,1,4,1,4,4,1,5,3,1,4,3,5,3,1,3,1,4,2,4,5,1,4,1,2,4,1,2,5,1,1,5,1,1,3,1,1,2,3,4,2,4,3,1
|
|
@ -0,0 +1,22 @@
|
|||
import fs from "fs-extra";
|
||||
import fp from "lodash/fp.js";
|
||||
import _ from "lodash";
|
||||
|
||||
export const processInput = (input) =>
|
||||
input.split(',').map( x => parseInt(x) );
|
||||
|
||||
export function solution(input,days = 80) {
|
||||
let fish = Array.from({length:8}, ()=>0);
|
||||
input.forEach( x => fish[x]++ );
|
||||
|
||||
for( let i = 0; i< days; i++ ) {
|
||||
const breeders = fish.shift();
|
||||
if(breeders ) {
|
||||
fish[8] = breeders;
|
||||
fish[6] = (fish[6] || 0) + breeders;
|
||||
}
|
||||
// console.log(fish);
|
||||
}
|
||||
|
||||
return _.sum(fish);
|
||||
};
|
|
@ -0,0 +1,18 @@
|
|||
import tap from "tap";
|
||||
import fs from "fs-extra";
|
||||
|
||||
import * as p1 from "./part1.mjs";
|
||||
|
||||
const sample = p1.processInput("3,4,3,1,2");
|
||||
const input = fs.readFile("input", "utf8").then(p1.processInput);
|
||||
|
||||
tap.test("part1", async (t) => {
|
||||
t.equal(p1.solution(await sample, 18), 26);
|
||||
t.equal(p1.solution(await sample), 5934);
|
||||
t.equal(p1.solution(await input), 358214);
|
||||
});
|
||||
|
||||
tap.test("part2", async (t) => {
|
||||
t.equal(p1.solution(await sample, 256), 26984457539);
|
||||
t.equal(p1.solution(await input, 256), 1622533344325);
|
||||
});
|
Loading…
Reference in New Issue