function getRandom() {
return parseInt(2 + (9 - 2 + 1) * Math.random());
}
function getCards() {
var arr = [];
var count = 5;
//while (count - -)
while (count–) {
arr.push(getRandom());
}
return arr;
}
function cal(cards) {
console.log(cards);
var s = 0;
var dict = {};
for (var i = 0; i < cards.length; i++) {
var ci = cards[i];
s += ci;
dict[ci] = dict[ci] === undefined ? 1 : dict[ci] + 1;
};
var point = s % 10;
var exists = false;
for (var i in dict) {
var other = (10 + point - i) % 10;
if (dict[other]) {
if ((other == i && dict[other] >= 2) || (other!=i&&dict[other] >= 1)) {
exists = true;
break;
}
}
}
return exists ? point : -1;
}
console.log(cal(getCards()));
// console.log(cal([6, 6, 9, 3, 9]));
最后是一组关于斗牛所有情况的概率表,望大家看了之后心里有点数(拿出jqk)
所有牌的组合数:658008
出现四条的组合数:360,概率 :0.05%
出现三条的组合数:25200,概率 :3.83%
出现牛十的组合数:42432,概率 :6.45%
出现牛九或牛八的组合数:87296,概率 :13.27%
出现牛一到牛七的组合数:306112,概率 :46.52%
出现没有牛的组合数:196608,概率 :29.88%
作者:那个方
来源:CSDN
原文:https://blog.csdn.net/weixin_44387879/article/details/87636579
版权声明:本文为博主原创文章,转载请附上博文链接!