Skip to content

Instantly share code, notes, and snippets.

@tenntenn
Created December 26, 2012 10:54
Show Gist options
  • Save tenntenn/4379584 to your computer and use it in GitHub Desktop.
Save tenntenn/4379584 to your computer and use it in GitHub Desktop.
ans := make(chan int)
go input(ans)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
count := 0
for i:= 1; i <= 10; i++ {
n := rnd.Intn(100)
m := rnd.Intn(100)
fmt.Printf("%2d : %2d + %2d = ", i, n, m)
select {
case nm := <-ans:
if nm == n+m {
fmt.Println(">> correct!")
count++
} else {
fmt.Println(">> wrong!!")
}
case <-time.After(5 * time.Second):
fmt.Println()
fmt.Println(">> timed out")
}
}
fmt.Println("-----------------")
fmt.Println("correct:", count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment