You are viewing a single comment's thread. Return to all comments →
JS
function range(a,b) { let prd = a,i = a; while (i++< b) { prd*=i; } return prd; } function comb(n, r) { if (n==r || r==0) return 1; else { r=(r < n-r) ? n-r : r; return range(r+1, n)/range(1,n-r); } } let value = input.split(' '); let p = parseFloat(value[0])/(parseFloat(value[1]) + parseFloat(value[0])); let q = 1-p, b =[]; for(let i = 3; i <= 6; i++) { let f = comb(6, i) * Math.pow(p, i) * Math.pow(q, (6 - i)); b.push(f); } console.log((b.reduce((sum, a) => sum + a, 0)).toFixed(3));
Day 4: Binomial Distribution I
You are viewing a single comment's thread. Return to all comments →
JS