- 元ネタ: http://qiita.com/y__sama/items/7c451dfd706f9b36729d
- 拙作PHP: http://qiita.com/shinderuman@github/items/7c432e8cb7719d35342a
- PHPが楽しかったので勉強がてらgoでも書いてみた
5個ずつキヨシる
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("キ・ヨ・シ!")
}
1個ずつキヨシる
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("キ・ヨ・シ!")
}