Skip to content

Instantly share code, notes, and snippets.

@shinderuman
Last active April 22, 2016 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinderuman/a1a77d6fccaf17685a71 to your computer and use it in GitHub Desktop.
Save shinderuman/a1a77d6fccaf17685a71 to your computer and use it in GitHub Desktop.
ズンドコキヨシ with Go (n番煎じ) ref: http://qiita.com/shinderuman@github/items/2ff67c2404647d2b7ea6
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("キ・ヨ・シ!")
}
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