diff --git a/index.html b/index.html index e96cdc9..875293a 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,16 @@ #graph { opacity: 0.5; float: right; + display: block; + } + #size { + opacity: 0.1; + clear: right; + float: right; + width: 12%; + text-align: center; + font-size: 4em; + cursor: pointer; } #counter { position: absolute; @@ -46,6 +56,9 @@
+
+ 3 +
@@ -65,6 +78,11 @@ var counter; var currValue = -1; + var numDigits = 3; + + function size() { + return document.getElementById("size"); + } function inp() { return document.getElementById("n"); @@ -78,12 +96,18 @@ return document.getElementById("output"); } - function next(p) { + // Get digit following p for chain size s (1, 2, or 3) + function next(p, s) { if (p < 1) return 0; - return parseInt(pi.substring(p - 1, p + 2)); + if (![1,2,3].includes(s)) s = 3; + return parseInt(pi.substring(p - 1, p + (s - 1))); } - function rand() { + // Get random number with up to s digits + function rand(s) { + if (![1,2,3].includes(s)) s = 3; + if (s == 1) return Math.floor(Math.random() * 9)+1; + if (s == 2) return Math.floor(Math.random() * 99)+1; // Pick randomly from weighted digits (favors digits that are less often encountered in pichains) return weightedDigits[Math.floor(Math.random() * weightedDigits.length)]; } @@ -99,7 +123,7 @@ } function openPiChain(event) { - window.open('pi-chain.html?q=' + (event ? event.target.innerText : inp().value)); + window.open('pi-chain.html?q=' + (event ? event.target.innerText : inp().value) + '&s=' + numDigits); } function reset(keepValue) { @@ -111,7 +135,7 @@ emptyDiv.innerHTML = " "; output().appendChild(emptyDiv); } - if (!keepValue) setValue(rand()); + if (!keepValue) setValue(rand(numDigits)); } function log(x) { @@ -122,6 +146,12 @@ scrollDown(); } + function toggleSize() { + numDigits = (numDigits % 3) + 1; + size().innerText = numDigits; + reset(false); + } + setTimeout(reset, 10); function clicked() { @@ -132,7 +162,7 @@ var n = parseInt(inp().value); if (n != currValue) reset(1); log(n); - var nextValue = next(n); + var nextValue = next(n, numDigits); counter++; updateCounter(); inp().value = nextValue; diff --git a/pi-chain.html b/pi-chain.html index a5d2dcc..42d60fd 100644 --- a/pi-chain.html +++ b/pi-chain.html @@ -24,29 +24,38 @@ const pi = "14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893"; -const mainLoop = [1, 141, 535, 224, 756, 721, 864, 875, 332, 628, 342, 171, 852, 101, 821, 425, 861, 783, 973]; +const mainLoop = [ + [], + [2, 41, 69, 64, 30, 95, 17, 38, 97, 6, 26, 83, 28, 27, 32], + [1, 141, 535, 224, 756, 721, 864, 875, 332, 628, 342, 171, 852, 101, 821, 425, 861, 783, 973] +]; const groupColors = { "main": "red", 0: "pink", 1: "grey", + 2: "grey", + 4: "grey", + 7: "blue", + 19: "grey", 46: "yellow", + 79: "grey", 92: "blue" } -function next(p) { +function next(p, s) { if (p < 1) return 0; - return parseInt(pi.substring(p - 1, p + 2)); + return parseInt(pi.substring(p - 1, p + (s-1))); } -function group(p) { +function group(p, s) { // Trace until chain then assign lowest value in chain let sequence = [p]; let found = false; let chain; let n = p; while (!found) { - n = next(n); + n = next(n, s); if (!sequence.includes(n)) { sequence.push(n); } else { @@ -59,22 +68,25 @@ let params = new URLSearchParams(document.location.search); let q = params.get('q'); +let s = parseInt(params.get('s')); +console.log(s); +if (![1,2,3].includes(s)) s = 3; +console.log(s); let nodes = []; let links = []; let groups = []; -for (var i=1; i<1000; i++) { - let g = group(i); - if (mainLoop.includes(i)) { - g = "main"; - } +for (var i=1; i