+/u/CompileBot swift
func prob(n: Int, probStart: Double, probPerGame: Double) -> Double {
return probStart + Double(n) * probPerGame
}
func probInTree(n: Int, probStart: Double, probPerGame: Double) -> Double {
var v: Double = 1
for i in 0...n-1 {
v *= 1 - prob(n: i, probStart: probStart, probPerGame: probPerGame)
}
return v
}
func gamesPerPack(winlossratio: Double, seasonpass: Bool) -> Double {
let probStart = 0.02
let probPerGame = (0.015 + 0.02 * winlossratio) / (winlossratio + 1) + (seasonpass ? 0.003 : 0.0)
var averageTries: Double = 1
let maxTries = Int((1 - probStart) / probPerGame)
for i in 1...maxTries {
averageTries += Double(i) * (prob(n: i, probStart: probStart, probPerGame: probPerGame) * probInTree(n: i, probStart: probStart, probPerGame: probPerGame))
}
return(averageTries)
}
printGpP(winlossratio: 1.0, seasonpass: false)
printGpP(winlossratio: 1.0, seasonpass: true)
printGpP(winlossratio: 0.0, seasonpass: false)
printGpP(winlossratio: 0.0, seasonpass: true)
printGpP(winlossratio: 10.0, seasonpass: false)
printGpP(winlossratio: 10.0, seasonpass: true)