Created
February 10, 2015 23:37
-
-
Save fkautz/e002063677228d14a21e to your computer and use it in GitHub Desktop.
Simple Probability Calculator
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println("Prob 12 (P=0.02): ", findProb(0.02, 12)) | |
fmt.Println("Prob 24 (P=0.02): ", findProb(0.02, 24)) | |
fmt.Println() | |
fmt.Println("Prob 12 (P=0.08): ", findProb(0.08, 12)) | |
fmt.Println("Prob 24 (P=0.08): ", findProb(0.08, 24)) | |
} | |
func findProb(p float64, n int) float64 { | |
probability := p | |
for i := 1; i < n; i++ { | |
probability = probability + p - probability*p | |
} | |
return probability | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment