Last active
April 22, 2016 00:54
-
-
Save shinderuman/a1a77d6fccaf17685a71 to your computer and use it in GitHub Desktop.
ズンドコキヨシ with Go (n番煎じ) ref: http://qiita.com/shinderuman@github/items/2ff67c2404647d2b7ea6
This file contains 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" | |
) | |
func main() { | |
z := "ズン" | |
d := "ドコ" | |
zd := [5]string{z, z, z, z, d} | |
ch := make(chan bool) | |
go func() { | |
for { | |
rand.Seed(time.Now().UnixNano()) | |
var zundoko [5]string | |
j := 0 | |
for _, i := range rand.Perm(len(zd)) { | |
zundoko[j] = zd[i] | |
j = j + 1 | |
} | |
if zd == zundoko { | |
ch <- true | |
break | |
} | |
} | |
}() | |
<-ch | |
fmt.Println("キ・ヨ・シ!") | |
} |
This file contains 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" | |
"reflect" | |
"time" | |
) | |
func main() { | |
z := "ズン" | |
d := "ドコ" | |
zd := []string{z, d} | |
zundoko := []string{z, z, z, z, d} | |
var zzdoko []string | |
rand.Seed(time.Now().UnixNano()) | |
for { | |
zzdoko = append(zzdoko, zd[rand.Intn(2)]) | |
if len(zzdoko) < 5 { | |
continue | |
} | |
if reflect.DeepEqual(zundoko, zzdoko[len(zzdoko)-5:]) { | |
fmt.Println(zzdoko) | |
break | |
} | |
} | |
fmt.Println("キ・ヨ・シ!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment