Skip to content

Instantly share code, notes, and snippets.

@Tarmean
Created August 8, 2019 10:07
Show Gist options
  • Save Tarmean/72ea71cd988f7e8efcee12e255e4ec8c to your computer and use it in GitHub Desktop.
Save Tarmean/72ea71cd988f7e8efcee12e255e4ec8c to your computer and use it in GitHub Desktop.
import Text.Printf
test :: IO ()
test = do
return ()
hyper possibleWins actualWins actualDraws = (winPerms * lossPerms) / totalPerms
where
winPerms = binomial possibleWins actualWins
lossPerms = binomial possibleLosses actualLosses
totalPerms = binomial possibleDraws actualDraws
possibleDraws = 30
possibleLosses = possibleDraws - possibleWins
actualLosses = actualDraws - actualWins
binomial :: Integer -> Integer -> Double
binomial n k = fromIntegral (fact n) / fromIntegral (fact k * fact (n - k))
fact = product . enumFromTo 1
atLeast1 :: Integer -> Integer -> Double
atLeast1 poss draws = sum [hyper poss i draws | i <- [1..poss]]
drawDarkest d = atLeast1 4 d * atLeast1 2 d
drawPlotTwist d = atLeast1 2 d * atLeast1 2 d
drawDorian d = atLeast1 2 d * atLeast1 1 d
anyOf a b = a * (1-b) + b * (1-a) + a * b
main :: IO ()
main = do
putStrLn " | Darkest Hour:| PlotTwist: | Either: | Dorian: "
forM_ [3..24] $ \i -> do
let
d = (drawDarkest i)
p = (drawPlotTwist i)
printf "%5i | %.10f | %.10f | %.10f | %.10f\n" i d p (anyOf d p) (drawDorian i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment