Count the routes to a sum

HTML for this example

Select the code and use your copy shortcut. Changes in this preview are temporary.

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Count the routes to a sum</title>
<style>
:root{color-scheme:light;--ink:#1e2f3c;--accent:#214f77;--wash:#e9f0f5;--paper:#fff;--line:#b7c8d2}*{box-sizing:border-box}[hidden]{display:none!important}body{margin:0;background:var(--wash);color:var(--ink);font:16px/1.6 system-ui,-apple-system,"Segoe UI",sans-serif;padding:24px 16px}main{max-width:960px;margin:auto;background:var(--paper);border:1px solid var(--line);border-top:7px solid var(--accent);box-shadow:0 12px 32px #1624320d}header{padding:26px 30px 20px;border-bottom:1px solid var(--line)}.kicker{font-weight:750;letter-spacing:.06em;color:var(--accent);margin:0 0 6px}h1{font-size:clamp(26px,5vw,38px);line-height:1.15;margin:0 0 12px;letter-spacing:-.025em}h2{font-size:22px;line-height:1.3;margin:0 0 16px}h3{font-size:18px;margin:0 0 10px}p{margin:0 0 14px}p:last-child{margin-bottom:0}.content{padding:26px 30px}.panel{padding:22px 0;border-bottom:1px solid var(--line)}.panel:first-child{padding-top:0}.panel:last-child{border-bottom:0}.cols{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:24px}.controls{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin:14px 0}.fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}label{display:block;font-weight:650;margin:10px 0}input,textarea{display:block;font:inherit;width:100%;min-width:0;background:#fff;color:var(--ink);padding:11px 12px;border:1px solid #7f94a5;border-radius:5px;margin-top:6px}textarea{resize:vertical}button{font:inherit;font-weight:700;border:2px solid var(--accent);border-radius:5px;color:var(--accent);background:var(--paper);padding:10px 16px;min-height:46px;cursor:pointer}button:hover,button[aria-pressed="true"]{background:var(--accent);color:#fff}button:focus-visible,input:focus-visible,textarea:focus-visible,summary:focus-visible{outline:3px solid #c77700;outline-offset:3px}.result{padding:16px 18px;border-left:5px solid var(--accent);background:var(--wash);margin:16px 0;white-space:pre-line}.metrics{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px;margin:16px 0}.metric{border-top:4px solid var(--accent);padding:12px;background:var(--wash)}.big{font-size:28px;font-weight:780;display:block;line-height:1.2;font-variant-numeric:tabular-nums}.rows{display:grid;gap:12px}.record{border:1px solid var(--line);padding:16px;border-radius:4px}.record h3{color:var(--accent)}.muted{color:#445867}.tag{display:inline-block;padding:3px 10px;background:var(--wash);border:1px solid var(--line);border-radius:30px}.route{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.chip{display:inline-block;border:2px solid var(--accent);border-radius:10px;padding:9px 14px;background:white;font-weight:750}.prime{background:#dff0df}.diagram{padding:20px;background:var(--wash);border:1px solid var(--line);margin:16px 0}summary{cursor:pointer;font-weight:700;padding:12px 0}details{border-top:1px dashed var(--line);margin-top:14px}.board{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:4px;margin:16px 0}.cell{font-size:16px;text-align:center;background:var(--wash);padding:6px 0;border:1px solid var(--line)}.cell.hit{background:var(--accent);color:white;font-weight:750}.staff{width:100%;height:auto;display:block;background:white}.staff text{font:18px system-ui;fill:var(--ink)}.shape-row{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}.shape-row button{padding:12px}.shape{display:block;margin:6px auto;background:var(--accent);height:62px;width:62px}.circle{border-radius:50%}.triangle{background:transparent;width:0;height:0;border-left:34px solid transparent;border-right:34px solid transparent;border-bottom:62px solid var(--accent)}.tray{border:2px solid var(--accent);padding:14px;margin:12px 0;border-radius:8px}.counters{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}.counter{border:1px solid var(--accent);border-radius:50%;width:46px;height:46px;display:inline-flex;align-items:center;justify-content:center;background:var(--wash);font-size:16px}.agenda{display:grid;grid-template-columns:1fr;gap:12px}.agenda p{border-left:4px solid var(--accent);padding:8px 14px;margin:0}.bar-row{margin:16px 0}.bar{height:24px;max-width:100%;background:var(--accent);border-radius:3px}.missing{padding:10px;border:2px dashed var(--accent)}.timeline-row{margin:16px 0}.track{position:relative;height:34px;background:var(--wash);border:1px solid var(--line);overflow:hidden}.segment{position:absolute;top:3px;height:26px;background:var(--accent)}.quote{font:26px/1.45 Georgia,serif;border-left:5px solid var(--accent);padding:18px;margin:18px 0;background:var(--wash)}.facts{padding:16px;background:var(--wash);border-top:4px solid var(--accent)}pre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:16px;font-family:ui-monospace,monospace;background:var(--wash);padding:16px}footer{padding:20px 30px;background:var(--wash);border-top:1px solid var(--line)}section,div,p,label,li{overflow-wrap:anywhere}ul,ol{padding-left:24px}.lesson{--accent:#4b3c79;--wash:#f0edf7}.meter{--accent:#176166;--wash:#e8f3f1}.meter header{background:#153f47;color:white}.meter .kicker{color:#ceebe5}.index{--accent:#3e566c;--wash:#edf1f5}.index .record{border-left:6px solid var(--accent)}.calendar{--accent:#824b25;--wash:#f6efe6}.montessori{--accent:#486047;--wash:#f1f1e5;--paper:#fffef7}.montessori h1,.montessori h2{font-family:Georgia,serif}.music{--accent:#343d75;--wash:#eef0f8}.music h1{font-family:Georgia,serif}.quotation{--accent:#204d79;--wash:#eaf0f7}.station{--accent:#6e522e;--wash:#f5efdf}.dice{--accent:#63398c;--wash:#f3edf9}.groups{--accent:#09685d;--wash:#e6f4ee}.wizard{--accent:#5b4595;--wash:#f1eef8}.wizard main{max-width:720px}.review{--accent:#7d3e4e;--wash:#f8edf0}.review h1{font-family:Georgia,serif}.factor{--accent:#286348;--wash:#e9f4ec}.service{--accent:#875118;--wash:#fcf0de}.statistics{--accent:#325891;--wash:#edf2fa}.hyperbole{--accent:#9a4928;--wash:#fbefe6}.hyperbole h1{font-family:Georgia,serif}@media(max-width:640px){body{padding:10px 8px}header,.content,footer{padding:20px}.cols{grid-template-columns:1fr;gap:16px}.metrics{grid-template-columns:1fr}.fields{grid-template-columns:1fr}.shape-row{gap:8px}.shape-row button{padding:8px}.shape{width:48px;height:48px}.shape.triangle{width:0;height:0;border-left-width:25px;border-right-width:25px;border-bottom-width:48px}.big{font-size:26px}.cell{padding:7px 0}.controls button{flex:1 1 auto}.quote{font-size:24px}}

</style></head><body class="dice"><main><header><p class="kicker">TWO DISTINGUISHABLE DICE / MODEL AND TRIALS</p><h1>Count the routes to a sum</h1><p>Theoretical model: fair, independent six-sided D1 and D2. Thirty-six ordered pairs, not eleven equally likely sums.</p></header><div class="content"><label for="prediction">Before counting: which is more likely, 8 or 3? Why?<textarea id="prediction" rows="3"></textarea></label><div class="controls"><button type="button" id="sum8">Highlight sum 8</button><button type="button" id="sum3">Highlight sum 3</button></div><div class="result" id="theory" aria-live="polite">Ready for an attempt.</div><div class="board" id="pair-grid" aria-label="Ordered pair grid; D1 rows 1 to 6, D2 columns 1 to 6"></div><section class="panel "><h2>Fictional worked sample</h2><p>F1 (2,6) → 8; F2 (1,2) → 3; F3 (4,4) → 8; F4 (6,1) → 7.</p><p>Sample: sum 8 = 2/4; sum 3 = 1/4. The final 7 remains in the denominator. These are not actual rolls or simulation output.</p></section><section class="panel "><h2>Separate manual trial log</h2><div class="fields"><label for="d1">D1 face, whole 1–6<input id="d1" type="number" value="" min="1" max="6" step="1"></label><label for="d2">D2 face, whole 1–6<input id="d2" type="number" value="" min="1" max="6" step="1"></label></div><button type="button" id="add">Add entered trial</button><div class="result" id="entry" aria-live="polite">No trial entered.</div><div class="result" id="frequency" aria-live="polite">Ready for an attempt.</div><div id="trials" class="rows"></div><button type="button" id="reset">Reset experiment</button></section><details id="teacher"><summary>Teacher explanation</summary><p>Five ordered pairs make 8 and two make 3. The theoretical denominator is 36; a trial frequency denominator is the number of recorded trials. A small sample does not revise the model or validate physical dice fairness.</p></details></div><footer><p>Original fictional teaching example. Entries are temporary and are cleared on reload; no responses are sent or saved.</p></footer></main><script>
(()=>{'use strict';const $=id=>document.getElementById(id);const text=(id,value)=>{$(id).textContent=value;};const on=(id,event,fn)=>$(id).addEventListener(event,fn);const clear=(ids,fn)=>ids.forEach(id=>on(id,'input',fn));const integer=(s,min,max)=>/^\d+$/.test(s)&&Number(s)>=min&&Number(s)<=max;const money=n=>'$'+n.toFixed(2);const normalize=s=>s.trim().toLowerCase().replace(/[.!?]$/,'');
let event=8,trials=[];function theory(){const pairs=[];let grid='';for(let first=1;first<=6;first++)for(let second=1;second<=6;second++){const hit=first+second===event;if(hit)pairs.push('('+first+','+second+')');grid+='<div class="cell '+(hit?'hit':'')+'">'+first+'+'+second+'<br>='+ (first+second)+'</div>';}$('pair-grid').innerHTML=grid;text('theory','Sum '+event+': '+pairs.length+'/36 favorable ordered pairs. '+pairs.join(', '));$('sum8').setAttribute('aria-pressed',String(event===8));$('sum3').setAttribute('aria-pressed',String(event===3));}function records(){const count=trials.length,eight=trials.filter(v=>v[0]+v[1]===8).length,three=trials.filter(v=>v[0]+v[1]===3).length;text('frequency',count?'Recorded trials: '+count+' · Sum 8: '+eight+'/'+count+' · Sum 3: '+three+'/'+count:'Recorded trials: 0 · Empirical frequencies undefined, not 0%.');$('trials').innerHTML=trials.map((pair,index)=>'<div class="record">Trial '+(index+1)+' · D1 '+pair[0]+' / D2 '+pair[1]+' · sum '+(pair[0]+pair[1])+'</div>').join('');}on('sum8','click',()=>{event=8;theory();});on('sum3','click',()=>{event=3;theory();});on('add','click',()=>{if(!integer($('d1').value,1,6)||!integer($('d2').value,1,6)){text('entry','Enter two whole faces from 1 to 6. No trial added.');return;}trials.push([Number($('d1').value),Number($('d2').value)]);text('entry','Entered pair added locally; no physical die rolled.');records();});on('reset','click',()=>{event=8;trials=[];['prediction','d1','d2'].forEach(id=>$(id).value='');$('teacher').open=false;text('entry','No trial entered.');theory();records();});theory();records();
})();
</script></body></html>