Last active
April 13, 2020 18:19
-
-
Save jonathonadler/8db3bb0025881ba9a740628f6b10186a to your computer and use it in GitHub Desktop.
Triangles
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" | |
| import "time" | |
| import "math/rand" | |
| const stickLength = 100 | |
| func main() { | |
| successes, failures := 0, 0 | |
| rand.Seed(time.Now().UnixNano()) | |
| fmt.Println("Starting loop") | |
| for i := 0; i < 100000000; i++ { | |
| a := stickLength * rand.Float64() | |
| b := stickLength * rand.Float64() | |
| c := stickLength - a - b | |
| if (a+b > c) && (b+c > a) && (a+c > b) { | |
| successes += 1 | |
| } else { | |
| failures += 1 | |
| } | |
| } | |
| fmt.Println("Successes : ", successes) | |
| fmt.Println("Failures : ", failures) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment