Initial commit
This commit is contained in:
3
Go/code_unoptimised/go.mod
Normal file
3
Go/code_unoptimised/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module example/hello
|
||||
|
||||
go 1.23
|
||||
29
Go/code_unoptimised/main.go
Normal file
29
Go/code_unoptimised/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
total_attempts int = 15_000_000
|
||||
successes_amount int = 0
|
||||
)
|
||||
|
||||
for i := 0; i < total_attempts; i++ {
|
||||
var (
|
||||
a int = rand.Intn(255)
|
||||
b int = rand.Intn(255)
|
||||
c int = rand.Intn(255)
|
||||
)
|
||||
|
||||
if a+b+c > 300 {
|
||||
successes_amount++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Iterations: %v\n", total_attempts)
|
||||
fmt.Printf("Valid sums: %v\n", successes_amount)
|
||||
fmt.Printf("Probability: %v\n", (float32(successes_amount) / float32(total_attempts)))
|
||||
}
|
||||
Reference in New Issue
Block a user