Skip to content

Instantly share code, notes, and snippets.

@jonathonadler
Last active April 13, 2020 18:19
Show Gist options
  • Select an option

  • Save jonathonadler/8db3bb0025881ba9a740628f6b10186a to your computer and use it in GitHub Desktop.

Select an option

Save jonathonadler/8db3bb0025881ba9a740628f6b10186a to your computer and use it in GitHub Desktop.
Triangles
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