先说结论
一等奖概率: 0.045208 (4.5%)
二等奖概率: 0.32307 (32.3%)
三等奖概率: 0.631722 (63.2%)
总和: 1
比起新年的活动,1-2等奖的中奖概率可以说翻倍了,我记得今年过年的中奖率从8个数字提升到15个数字,中奖率才35%
(但是我依旧什么都没有)
感兴趣的同学可以让AI跑一下发1贴和2贴的概率是多少,我就摸鱼去了
R语言线上执行网页https://rtool.cn/run/r400.html
相关代码如下
- # 定义颜色及其概率
- colors <- c("金色", "黑色", "白色", "绿色", "蓝色", "粉色",
- "橙色", "红色", "紫色", "青色")
- probs <- c(0.01, 0.04, 0.04, 0.13, 0.13, 0.13,
- 0.13, 0.13, 0.13, 0.13)
- # 生成所有有序组合(3 次抽取,每次独立)
- results <- expand.grid(rep(list(colors), 3), stringsAsFactors = FALSE)
- colnames(results) <- c("c1", "c2", "c3")
- # 计算每个结果的概率(乘积)
- results$prob <- apply(results, 1, function(x) {
- prod(probs[match(x, colors)])
- })
- # 判断每个结果的中奖等级(优先级:一 > 二 > 三)
- award <- character(nrow(results))
- for (i in 1:nrow(results)) {
- triple <- as.character(results[i, 1:3])
- freq <- table(triple)
- n_unique <- length(freq)
-
- # ----- 一等奖 -----
- # 条件1:含有金色(至少一次)
- # 条件2:三个颜色相同
- if ("金色" %in% triple || n_unique == 1) {
- award[i] <- "一等奖"
- next
- }
-
- # ----- 二等奖 -----
- # 条件1:两个相同 + 一个不同(且不含金色,因为金色已过滤)
- if (n_unique == 2 && max(freq) == 2) {
- award[i] <- "二等奖"
- next
- }
- # 条件2:黑、白、其他(三个不同颜色,且同时包含黑和白)
- if (n_unique == 3 && "黑色" %in% triple && "白色" %in% triple) {
- award[i] <- "二等奖"
- next
- }
-
- # ----- 三等奖 -----
- # 三个不同颜色(此时一定不含金色,也不含黑+白组合)
- if (n_unique == 3) {
- award[i] <- "三等奖"
- next
- }
-
- # 理论上不应有未覆盖的情况,但以防万一
- award[i] <- "无奖"
- }
- # 汇总概率
- prob_first <- sum(results$prob[award == "一等奖"])
- prob_second <- sum(results$prob[award == "二等奖"])
- prob_third <- sum(results$prob[award == "三等奖"])
- cat("一等奖概率:", prob_first, "\n")
- cat("二等奖概率:", prob_second, "\n")
- cat("三等奖概率:", prob_third, "\n")
- cat("总和:", prob_first + prob_second + prob_third, "\n")
复制代码
|