Skip to content

Instantly share code, notes, and snippets.

@meru-akimbo
Last active July 4, 2018 17:37
Show Gist options
  • Save meru-akimbo/ec7a2f70b54257d8d3f83c1ed009a9d8 to your computer and use it in GitHub Desktop.
Save meru-akimbo/ec7a2f70b54257d8d3f83c1ed009a9d8 to your computer and use it in GitHub Desktop.
Monty Hall problem
package main
import (
"fmt"
"math/rand"
"time"
)
type Answer struct {
X, Y int
}
type Choice struct {
X, Y int
}
type Marcy struct {
X, Y int
}
type LastChoice struct {
X, Y int
}
func main() {
change_hit := 0
keep_hit := 0
i := 1
for i <= 100 {
rand.Seed(time.Now().UnixNano())
answer := Answer{rand.Intn(9), rand.Intn(9)}
choice := Choice{rand.Intn(9), rand.Intn(9)}
var marcy Marcy
if choice.X == answer.X && choice.Y == answer.Y {
marcy = Marcy{rand.Intn(9), rand.Intn(9)}
for marcy.X == answer.X && marcy.Y == answer.Y {
marcy = Marcy{rand.Intn(9), rand.Intn(9)}
}
} else {
marcy = Marcy{answer.X, answer.Y}
}
change_choice := LastChoice{marcy.X, marcy.Y}
if change_choice.X == answer.X && change_choice.Y == answer.Y {
change_hit++
} else {
keep_hit++
}
i++
}
fmt.Println("change hit:", change_hit)
fmt.Println("keep hit:", keep_hit)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment