• API
• FAQ
• Tools
• Archive
SHARE
TWEET # binomial calculator a guest Aug 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function combination (a, b) {
2.   return factorial(a) / (factorial(a - b) * factorial(b));
3. }
4.
5. function factorial (a) {
6.   let res = 1;
7.   while (a) {
8.      res *= a;
9.      a--;
10.   }
11.   return res;
12. }
13.
14. function generalBinomialTerm (total, n, x, y) {
15.   if (total < n || total < 0 || n < 0 || x < 0 || y < 0 || typeof x !== 'number' || typeof y !== 'number' || typeof x !== 'number' || typeof y !== 'number') return;
16.   return combination(total, n) * (x ** n) * (y ** (total - n));
17. }
18.
19. function binomialSum (from, to, total, x, y) {
20.   let sum = 0;
21.   for (let i = from; i <= to; i++) {
22.     sum += generalBinomialTerm(total, i, x, y);
23.   }
24.   return sum;
25. }
26.
27. function dice (amount, dice, difficulty, win) {
28.   return ('D' + dice + ' DIFFICULTY ' + difficulty + ' SKILL LEVEL ' + amount + '= ' + binomialSum(difficulty, amount, amount, win, (1 - win)) + '\n');
29. }
30.
31. function dices (list, level, difficulty, win) {
32.   let probabilities = '';
33.   lists.forEach(a => { probabilities += dice(level, a, difficulty, win) });
34.   console.log(probabilities);
35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top