aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / public / js / turing.js
| 1 | (function(){ |
| 2 | "use strict"; |
| 3 | var $ = function(id){ return document.getElementById(id); }; |
| 4 | |
| 5 | /* ---------- scroll progress ---------- */ |
| 6 | var prog = $("progress"); |
| 7 | function onScroll(){ |
| 8 | var h = document.documentElement; |
| 9 | var p = h.scrollTop / (h.scrollHeight - h.clientHeight); |
| 10 | prog.style.width = (p*100).toFixed(2) + "%"; |
| 11 | } |
| 12 | window.addEventListener("scroll", onScroll, {passive:true}); onScroll(); |
| 13 | |
| 14 | /* ---------- reveal on scroll ---------- */ |
| 15 | var io = new IntersectionObserver(function(es){ |
| 16 | es.forEach(function(e){ if(e.isIntersecting){ e.target.classList.add("visible"); io.unobserve(e.target); } }); |
| 17 | },{threshold:.12}); |
| 18 | document.querySelectorAll(".reveal").forEach(function(el){ io.observe(el); }); |
| 19 | |
| 20 | /* ---------- hero particle field: scattered bits coalescing ---------- */ |
| 21 | var cv = $("field"), ctx = cv.getContext("2d"), W=0, H=0, parts=[]; |
| 22 | function sizeCanvas(){ |
| 23 | W = cv.width = cv.offsetWidth; H = cv.height = cv.offsetHeight; |
| 24 | parts = []; |
| 25 | var n = Math.max(90, Math.min(240, Math.floor(W*H/9000))); |
| 26 | for(var i=0;i<n;i++){ |
| 27 | parts.push({ |
| 28 | hx: Math.random()*W, hy: Math.random()*H, |
| 29 | sa: Math.random()*Math.PI*2, |
| 30 | sr: 26 + Math.random()*Math.min(W,H)*0.30, |
| 31 | s: .7 + Math.random()*1.9, |
| 32 | sp: .5 + Math.random()*.9, |
| 33 | c: Math.random()<.72 ? "45,127,249" : "0,229,153", |
| 34 | dr: (Math.random()-.5)*.14 |
| 35 | }); |
| 36 | } |
| 37 | } |
| 38 | sizeCanvas(); window.addEventListener("resize", sizeCanvas); |
| 39 | function ease(x){ return x<.5 ? 2*x*x : 1-Math.pow(-2*x+2,2)/2; } |
| 40 | var t0 = performance.now(); |
| 41 | function frame(now){ |
| 42 | var t = ((now - t0)/16000) % 1; /* 16s loop */ |
| 43 | var k = t<.5 ? ease(t*2) : ease((1-t)*2); /* 0 scattered, 1 coalesced */ |
| 44 | ctx.clearRect(0,0,W,H); |
| 45 | ctx.globalCompositeOperation = "lighter"; |
| 46 | var cx = W/2, cy = H*0.40, rot = now*0.00012; |
| 47 | for(var i=0;i<parts.length;i++){ |
| 48 | var p = parts[i]; |
| 49 | p.hx += p.dr; p.hy += p.dr*.6; |
| 50 | if(p.hx<0)p.hx=W; if(p.hx>W)p.hx=0; if(p.hy<0)p.hy=H; if(p.hy>H)p.hy=0; |
| 51 | var a = p.sa + rot*p.sp; |
| 52 | var tx = cx + Math.cos(a)*p.sr, ty = cy + Math.sin(a)*p.sr*.72; |
| 53 | var x = p.hx + (tx-p.hx)*k, y = p.hy + (ty-p.hy)*k; |
| 54 | var al = .16 + .6*k; |
| 55 | ctx.beginPath(); ctx.arc(x, y, p.s*(0.7+0.9*k), 0, 6.2832); |
| 56 | ctx.fillStyle = "rgba("+p.c+","+al.toFixed(3)+")"; ctx.fill(); |
| 57 | } |
| 58 | ctx.globalCompositeOperation = "source-over"; |
| 59 | requestAnimationFrame(frame); |
| 60 | } |
| 61 | requestAnimationFrame(frame); |
| 62 | |
| 63 | /* ---------- GAME 1: crack the code ---------- */ |
| 64 | var g1rules = document.querySelectorAll("#g1-rules .rule-btn"); |
| 65 | var g1tiles = [$("g1-h0"),$("g1-h1"),$("g1-h2")]; |
| 66 | function paintTiles(vals, ok){ |
| 67 | g1tiles.forEach(function(t,i){ |
| 68 | t.textContent = vals[i]; |
| 69 | t.style.borderStyle = "solid"; |
| 70 | if(ok===true){ t.style.background="rgba(0,229,153,.14)"; t.style.borderColor="#00e599"; t.style.color="#00e599"; } |
| 71 | else if(ok===false){ t.style.background="rgba(255,93,93,.12)"; t.style.borderColor="#ff5d5d"; t.style.color="#ff5d5d"; } |
| 72 | }); |
| 73 | } |
| 74 | function resetTiles(){ |
| 75 | g1tiles.forEach(function(t){ |
| 76 | t.textContent="?"; t.style.background=""; t.style.borderColor=""; t.style.color=""; t.style.borderStyle=""; |
| 77 | }); |
| 78 | } |
| 79 | var g1data = { |
| 80 | good: { vals:["28","33","38"], ok:true, cls:"good", |
| 81 | verdict:"+2.6 T. The rule earns its keep.", |
| 82 | math:"3 sealed events nailed <b>+3.0</b><br>rule rent, 4 words × 0.1 <b>−0.4</b><br>= <b>+2.6 T</b>", |
| 83 | explain:"<strong>Why it wins:</strong> four words that keep working on data nobody has seen. The rent is tiny and the prediction is total. This is what a Turing rewards." }, |
| 84 | memo: { vals:["23","23","23"], ok:false, cls:"bad", |
| 85 | verdict:"−1.0 T. Memory is not understanding.", |
| 86 | math:"0 sealed events predicted <b>+0.0</b><br>rule rent, 10 words × 0.1 <b>−1.0</b><br>= <b>−1.0 T</b>", |
| 87 | explain:"<strong>Why it fails:</strong> the rule only recites what was already shown, so when it meets sealed numbers it just repeats the last thing it saw. Ten words of rent, zero prediction. Negative Turings." }, |
| 88 | wrong: { vals:["43","83","163"], ok:false, cls:"bad", |
| 89 | verdict:"−0.5 T. Confident and wrong.", |
| 90 | math:"0 sealed events predicted <b>+0.0</b><br>rule rent, 5 words × 0.1 <b>−0.5</b><br>= <b>−0.5 T</b>", |
| 91 | explain:"<strong>Why it fails:</strong> it sounds like a rule, but the sealed data disagrees with every guess. The scorer does not grade confidence. It grades sealed predictions minus rent." } |
| 92 | }; |
| 93 | g1rules.forEach(function(btn){ |
| 94 | btn.addEventListener("click", function(){ |
| 95 | var d = g1data[btn.getAttribute("data-rule")]; |
| 96 | g1rules.forEach(function(b){ b.disabled=true; b.classList.add("dim"); }); |
| 97 | btn.classList.remove("dim"); btn.classList.add("picked"); |
| 98 | paintTiles(d.vals, d.ok); |
| 99 | $("g1-score").textContent = d.cls==="good" ? "+2.6 T" : (btn.getAttribute("data-rule")==="memo" ? "-1.0 T" : "-0.5 T"); |
| 100 | var v=$("g1-verdict"); v.className="verdict "+d.cls; v.innerHTML=d.verdict; |
| 101 | $("g1-math").innerHTML=d.math; $("g1-explain").innerHTML=d.explain; |
| 102 | $("g1-result").classList.add("show"); |
| 103 | }); |
| 104 | }); |
| 105 | $("g1-again").addEventListener("click", function(){ |
| 106 | g1rules.forEach(function(b){ b.disabled=false; b.classList.remove("dim","picked"); }); |
| 107 | resetTiles(); $("g1-result").classList.remove("show"); $("g1-score").textContent="--"; |
| 108 | }); |
| 109 | |
| 110 | /* ---------- RULE LAB ---------- */ |
| 111 | var rGain=$("r-gain"), rCost=$("r-cost"); |
| 112 | function lab(){ |
| 113 | var g=+rGain.value, c=+rCost.value, rent=c*0.1, t=g-rent; |
| 114 | $("o-gain").textContent=g; $("o-cost").textContent=c; |
| 115 | var tv=$("lab-t"); |
| 116 | var txt=(t>0?"+":"")+(Math.round(t*10)/10).toFixed(1)+" T"; |
| 117 | tv.textContent=txt; |
| 118 | tv.className="tval "+(t>0?"pos":t<0?"neg":"zero"); |
| 119 | $("lab-f-gain").textContent=g; $("lab-f-cost").textContent=rent.toFixed(1); |
| 120 | var ft=$("lab-f-t"); ft.textContent=txt; ft.style.color=t>0?"#00e599":t<0?"#ff5d5d":"#94a3b8"; |
| 121 | var w=Math.max(3,Math.min(100,(t+4)/16*100)); |
| 122 | var bar=$("lab-bar"); bar.style.width=w+"%"; |
| 123 | bar.style.background=t>0?"linear-gradient(90deg,#2d7ff9,#00e599)":t<0?"linear-gradient(90deg,#7f1d1d,#ff5d5d)":"#475569"; |
| 124 | var note=$("lab-note"), msg; |
| 125 | if(t>=8) msg="Theory territory. Short, powerful, keeps predicting on unseen data."; |
| 126 | else if(t>=3) msg="A solid explanation. It earns its keep with room to spare."; |
| 127 | else if(t>0) msg="Positive but thin. Can you say it in fewer words?"; |
| 128 | else if(t===0) msg="Exactly at baseline. It predicts nothing beyond its own cost."; |
| 129 | else msg="Memorizer zone: longer than the insight it carries. The scorer charges rent."; |
| 130 | note.textContent=msg; |
| 131 | } |
| 132 | rGain.addEventListener("input", lab); rCost.addEventListener("input", lab); lab(); |
| 133 | |
| 134 | /* ---------- GAME 2: beat the memorizer ---------- */ |
| 135 | var rounds=[ |
| 136 | {q:"Duel 1: the number game", sub:"A machine watched 3, 8, 13, 18, 23, then sealed data.", |
| 137 | a:{who:"CANDIDATE A", text:"\u201Cadd 5 each time\u201D (4 words)"}, |
| 138 | b:{who:"CANDIDATE B", text:"\u201Cthe numbers are 3, 8, 13, 18, 23, 28, 33, 38\u201D (12 words)"}, |
| 139 | correct:"a", |
| 140 | why:"<strong>A wins.</strong> Both name the hidden numbers, but B is three times longer and carries no reusable rule. On a brand-new game, A still works and B knows nothing. Turings reward the rule, not the recital."}, |
| 141 | {q:"Duel 2: the night sky", sub:"Two explanations of dots moving overhead.", |
| 142 | a:{who:"CANDIDATE A", text:"\u201Cplanets orbit the sun in ellipses\u201D (6 words)"}, |
| 143 | b:{who:"CANDIDATE B", text:"\u201C4,000 sky-dots move along these 4,000 listed paths\u201D (plus a 4,000-line table)"}, |
| 144 | correct:"a", |
| 145 | why:"<strong>A wins.</strong> Six words that predict every future night. B is a phone book of the sky: enormous rent, zero generalization. This is the whole game in one duel."}, |
| 146 | {q:"Duel 3: the twist", sub:"Now length is not the whole story.", |
| 147 | a:{who:"CANDIDATE A", text:"\u201Cadd 5 each time\u201D (4 words), predicts 3 sealed events"}, |
| 148 | b:{who:"CANDIDATE B", text:"\u201Cadd 5 each time, except after primes add 7\u201D (10 words), predicts 9 sealed events"}, |
| 149 | correct:"b", |
| 150 | why:"<strong>B wins.</strong> 9 predicted minus 1.0 rent = +8.0 T, against A's 3 minus 0.4 = +2.6 T. A longer rule CAN win, but only if the extra words buy more prediction than they cost. That is what \u201Cnet\u201D means."} |
| 151 | ]; |
| 152 | var g2score=0, g2done=0; |
| 153 | var wrap=$("g2-rounds"); |
| 154 | rounds.forEach(function(r,i){ |
| 155 | var card=document.createElement("div"); card.className="quiz-card"; |
| 156 | card.innerHTML='<p class="quiz-q">'+r.q+'</p><p class="quiz-sub">'+r.sub+'</p>'+ |
| 157 | '<div class="duel"><button data-pick="a"><span class="who">'+r.a.who+'</span>'+r.a.text+'</button>'+ |
| 158 | '<button data-pick="b"><span class="who">'+r.b.who+'</span>'+r.b.text+'</button></div>'+ |
| 159 | '<div class="quiz-why"></div>'; |
| 160 | wrap.appendChild(card); |
| 161 | var btns=card.querySelectorAll("button"), why=card.querySelector(".quiz-why"), open=false; |
| 162 | btns.forEach(function(b){ |
| 163 | b.addEventListener("click", function(){ |
| 164 | if(open) return; open=true; g2done++; |
| 165 | var pick=b.getAttribute("data-pick"), win=pick===r.correct; |
| 166 | btns.forEach(function(x){ |
| 167 | x.disabled=true; |
| 168 | if(x.getAttribute("data-pick")===r.correct) x.classList.add("right"); else x.classList.add("wrong"); |
| 169 | }); |
| 170 | if(win){ g2score++; } |
| 171 | why.innerHTML=(win?"<strong style='color:#00e599'>Correct. </strong>":"<strong style='color:#ff5d5d'>Not this one. </strong>")+r.why; |
| 172 | why.classList.add("show"); |
| 173 | $("g2-score").textContent=g2score+" / 3"; |
| 174 | if(g2done===3){ |
| 175 | var msg=g2score===3?"Flawless. You score explanations like the instrument does.": |
| 176 | g2score===2?"Strong. Round 3 tricks almost everyone the first time.": |
| 177 | "The twist got you. Replay it: net means prediction minus rent, always."; |
| 178 | var d=document.createElement("p"); d.className="explain"; d.style.marginTop="22px"; |
| 179 | d.innerHTML="<strong>"+msg+"</strong>"; |
| 180 | wrap.appendChild(d); |
| 181 | } |
| 182 | }); |
| 183 | }); |
| 184 | }); |
| 185 | |
| 186 | /* ---------- big number count-up ---------- */ |
| 187 | var bignum=$("bignum"), counted=false; |
| 188 | function fmt(n){ return n.toLocaleString("en-US",{minimumFractionDigits:3,maximumFractionDigits:3}); } |
| 189 | var bio=new IntersectionObserver(function(es){ |
| 190 | es.forEach(function(e){ |
| 191 | if(e.isIntersecting && !counted){ |
| 192 | counted=true; var target=2559679.825, start=performance.now(), dur=2200; |
| 193 | (function tick(now){ |
| 194 | var p=Math.min(1,(now-start)/dur), v=target*(1-Math.pow(1-p,3)); |
| 195 | bignum.textContent=fmt(v); |
| 196 | if(p<1) requestAnimationFrame(tick); else bignum.textContent=fmt(target); |
| 197 | })(start); |
| 198 | var gc=$("gcurve"); |
| 199 | gc.style.transition="stroke-dashoffset 2.2s ease .3s"; gc.style.strokeDashoffset="0"; |
| 200 | bio.disconnect(); |
| 201 | } |
| 202 | }); |
| 203 | },{threshold:.3}); |
| 204 | bio.observe(document.querySelector(".bigstat")); |
| 205 | var cio=new IntersectionObserver(function(es){ |
| 206 | es.forEach(function(e){ |
| 207 | if(e.isIntersecting){ |
| 208 | var gc=$("gcurve"); |
| 209 | gc.style.transition="stroke-dashoffset 2.2s ease .3s"; gc.style.strokeDashoffset="0"; |
| 210 | cio.disconnect(); |
| 211 | } |
| 212 | }); |
| 213 | },{threshold:.4}); |
| 214 | cio.observe($("gcurve")); |
| 215 | })(); |