xxxxxxxxxx
58
let input = [3,4,3,1,2];
input = [4,1,3,2,4,3,1,4,4,1,1,1,5,2,4,4,2,1,2,3,4,1,2,4,3,4,5,1,1,3,1,2,1,4,1,1,3,4,1,2,5,1,4,2,2,1,1,1,3,1,5,3,1,2,1,1,1,1,4,1,1,1,2,2,1,3,1,3,1,3,4,5,1,2,2,1,1,1,4,1,5,1,3,1,3,4,1,3,2,3,4,4,4,3,4,5,1,3,1,3,5,1,1,1,1,1,2,4,1,2,1,1,1,5,1,1,2,1,3,1,4,2,3,4,4,3,1,1,3,5,3,1,1,5,2,4,1,1,3,5,1,4,3,1,1,4,2,1,1,1,1,1,1,3,1,1,1,1,1,4,5,1,2,5,3,1,1,3,1,1,1,1,5,1,2,5,1,1,1,1,1,1,3,5,1,3,2,1,1,1,1,1,1,1,4,5,1,1,3,1,5,1,1,1,1,3,3,1,1,1,4,4,1,1,4,1,2,1,4,4,1,1,3,4,3,5,4,1,1,4,1,3,1,1,5,5,1,2,1,2,1,2,3,1,1,3,1,1,2,1,1,3,4,3,1,1,3,3,5,1,2,1,4,1,1,2,1,3,1,1,1,1,1,1,1,4,5,5,1,1,1,4,1,1,1,2,1,2,1,3,1,3,1,1,1,1,1,1,1,5];
let newBorn = 8;
let old = 6;
function setup() {
createCanvas(1, 1);
solve();
}
function draw() {
background(220);
}
function solve() {
let counters = [0, 0, 0, 0, 0, 0, 0, 0, 0];
// count num fish on each day
for(let i = 0; i < input.length; i ++) {
counters[input[i]] ++;
}
for(let i = 0; i < 256; i ++) {
let spawned = 0;
for(let d = 0; d < counters.length - 1; d ++) {
curr = counters[d];
counters[d] = counters[(d + 1)];
if(d == 0) {
spawned = curr;
}
}
counters[8] = spawned;
counters[6] += spawned;
}
let total = 0;
for(let i = 0; i < counters.length; i ++) {
total += counters[i];
}
print(total);
// for(let i = 0; i < 80; i ++) {
// generate(input);
// }
// print(input.length);
}
function generate(list) {
for(let i = list.length-1; i >=0; i --) {
list[i] --;
if(list[i] < 0) {
list[i] = old;
list.push(newBorn);
}
}
}