Last active
February 4, 2022 17:25
-
-
Save mayonesa/22ca2aeba904b2403922b4ff1a8a43ea to your computer and use it in GitHub Desktop.
Probability of the result of 9 4-sided (pyramidal) dice (faces: 1 -> 4) is greater than the result of 6 6-sided (cubic) dice (faces: 1 -> 6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object PyramidWins extends App { | |
private def pdf(v: IndexedSeq[Int]) = | |
v.groupBy(identity).map { pair => | |
(pair._1, pair._2.size / v.size.toFloat) | |
} | |
private val pyramids = pdf(for { | |
p1 <- 1 to 4 | |
p2 <- 1 to 4 | |
p3 <- 1 to 4 | |
p4 <- 1 to 4 | |
p5 <- 1 to 4 | |
p6 <- 1 to 4 | |
p7 <- 1 to 4 | |
p8 <- 1 to 4 | |
p9 <- 1 to 4 | |
} yield p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9) | |
private val cubics = pdf(for { | |
c1 <- 1 to 6 | |
c2 <- 1 to 6 | |
c3 <- 1 to 6 | |
c4 <- 1 to 6 | |
c5 <- 1 to 6 | |
c6 <- 1 to 6 | |
} yield c1 + c2 + c3 + c4 + c5 + c6) | |
private val pyrWinsPercs = for { | |
p <- pyramids | |
c <- cubics | |
} yield if (p._1 > c._1) p._2 * c._2 else 0 | |
println(pyrWinsPercs.sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment