const qualitySetting = [
{ probability: 0.9, minimumGuarantee: 5 }, //绿色 0
{ probability: 0.75, minimumGuarantee: 5 }, //蓝色 1
{ probability: 0.55, minimumGuarantee: 5 }, //紫色 2
{ probability: 0.25, minimumGuarantee: 10 }, //金色 3
{ probability: 0.15, minimumGuarantee: 10 }, //红色 4
{ probability: 0.03, minimumGuarantee: 10 }, //彩色 5
];
let map: any = {
["-1"]: "普通",
0: "绿色",
1: "蓝色",
2: "紫色",
3: "金色",
4: "红色",
5: "彩色",
};
Object.entries(map).forEach(([k, v]) => {
map[v as any] = k;
});
function count(quality: number, n: number): number {
console.log(`conut of '${map[quality]}'`, n);
if (quality < 0) {
return n;
}
if (quality > 5 || quality < 0) {
throw new Error("有问题");
}
const probability = qualitySetting[quality].probability;
const numberOfSuperiors = (2 / probability) * n;
return count(quality - 1, numberOfSuperiors);
}
console.log(count(5, 1));