10,000 numbers - how-many-times-can-you-add-up-the...SPOILER
In response to: https://thefiddler.substack.com/p/how-many-times-can-you-add-up-the
let sum, myArray, opac;
let radialMode = true;
function setup() {
createCanvas(600, 600);
c = width * 0.9;
gSize = 100;
opac = 255;
}
function draw() {
background(10, 30, 40);
translate(width / 2, height / 2);
count = [];
cnt2 = 0;
cnt3 = 0;
for (let i = 0; i < gSize; i++) {
for (let j = 0; j < gSize; j++) {
cnt3++;
myArray = str(cnt3).split("");
cnt = 0;
noStroke();
while (myArray.length > 1) {
sum = 0;
for (let k = 0; k < myArray.length; k++) {
sum = sum + int(myArray[k]);
}
myArray = str(sum).split("");
cnt++;
}
if (!radialMode) {
x = -width / 2 + (j * width) / gSize + width / gSize / 2;
y = -height / 2 + (i * width) / gSize + width / gSize / 2;
if (cnt === 0) {
fill(20, 30, 40, opac);
} else if (cnt === 1) {
fill(50, 70, 80, opac);
} else if (cnt === 2) {
fill(120, 150, 180, opac);
} else if (cnt === 3) {
fill(230, 240, 250);
count[cnt2] = [i, cnt];
cnt2++;
}
circle(x, y, width / gSize);
} else {
if (cnt === 0) {
fill(20, 30, 40, opac);
} else if (cnt === 1) {
fill(50, 70, 80, opac);
} else if (cnt === 2) {
fill(120, 150, 180, opac);
} else if (cnt === 3) {
fill(230, 240, 250);
count[cnt2] = [i, cnt];
cnt2++;
}
circle(
((cnt3 * cnt * c) / 60000) * cos((TWO_PI / 100) * cnt3),
((cnt3 * cnt * c) / 60000) * sin((TWO_PI / 100) * cnt3),
cnt3 / 2000
);
}
}
}
if (frameCount == 1) {
console.log("There are " + count.length + " where f(N)=3.");
}
}
function mousePressed() {
if (opac === 255) {
opac = 0;
} else {
opac = 255;
}
draw();
}
function keyPressed() {
radialMode = !radialMode;
setup();
draw();
}