Last active
May 18, 2016 04:29
-
-
Save utahta/69f91fbb3d6d18ea392a to your computer and use it in GitHub Desktop.
ズンドコ with Golang
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" | |
| "math/rand" | |
| "time" | |
| ) | |
| const ( | |
| zun = "ズン" | |
| doko = "ドコ" | |
| ) | |
| var zundoko = []string{zun, doko} | |
| func main() { | |
| rand.Seed(time.Now().UnixNano()) | |
| zndk := make(chan string) | |
| quit := make(chan bool) | |
| go func() { | |
| for { | |
| z1, z2, z3, z4, d := <-zndk, <-zndk, <-zndk, <-zndk, <-zndk | |
| fmt.Println(z1, z2, z3, z4, d) | |
| if zun == z1 && zun == z2 && zun == z3 && zun == z4 && doko == d { | |
| break | |
| } | |
| } | |
| quit <- true | |
| }() | |
| for { | |
| select { | |
| case <-quit: | |
| fmt.Println("キ・ヨ・シ!") | |
| return | |
| default: | |
| go func() { | |
| zndk <- zundoko[rand.Int()%2] | |
| }() | |
| } | |
| time.Sleep(time.Nanosecond) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment