Last active
January 4, 2020 23:33
-
-
Save henryamster/574990f42676d11cdb866eef187e2bd0 to your computer and use it in GitHub Desktop.
dice roll simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r=1e2,a=[];i=_=>Math.floor(Math.random()*6);di=(v,i,s)=>s.indexOf(v)==i;for(p=0;p<r;p++){a.push(i()+1)};b=a.reduce((a,i)=>a+=i);t=(`\nDICE SIM \nmax: ${Math.max(...a)}\nmin: ${Math.min(...a)}\nmean: ${(b/r)}\nmedian: ${(Math.max(...a)-Math.min(...a))/2}\nmode: ${(a.filter(di).map(x=>[x, a.filter(y=>y===x).length]).sort((a,b)=>a[1]<b[1]?1:-1)[0].join(' -> '))}\nsample: ${r}\nst.dev: ${ Math.sqrt(a.map(x=>{d=x-(b/r);return d*d}).reduce((i,a)=>i+=a)).toFixed(4)}\nresults: ${ a.filter(di).map(x=> [x, a.filter(y=>y===x).length]).sort((a,b)=>a[1]<b[1]?1:-1).map((z,i)=>String.fromCharCode(0x2680+z[0]-1)+':'+z[1]).join(' ')}\nrolls:\n${a.map((x,i)=>`${`${String.fromCharCode(0x267F+x)}`}`).join(' ')}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for(r=1e4,a=[],i=(a=>Math.floor(6*Math.random())),di=((a,n,r)=>r.indexOf(a)==n),p=0;p<r;p++)a.push(i()+1);b=a.reduce((a,n)=>a+=n),t=
\nDICE SIM \nmax: ${Math.max(...a)}\nmin: ${Math.min(...a)}\nmean: ${b/r}\nmedian: ${(Math.max(...a)-Math.min(...a))/2}\nmode: ${a.filter(di).map(n=>[n,a.filter(a=>a===n).length]).sort((a,n)=>a[1]<n[1]?1:-1)[0].join(" -> ")}\nsample: ${r}\nst.dev: ${Math.sqrt(a.map(a=>(d=a-b/r,d*d)).reduce((a,n)=>a+=n)).toFixed(4)}\nresults: ${a.filter(di).map(n=>[n,a.filter(a=>a===n).length]).sort((a,n)=>a[1]<n[1]?1:-1).map((a,n)=>String.fromCharCode(9856+a[0]-1)+":"+a[1]).join(" ")}\nrolls:\n${a.map((a,n)=>
${${String.fromCharCode(9855+a)}
}).join(" ")}
;--- minif ---