LoginSignup
6
6

More than 5 years have passed since last update.

ズンドコキヨシ with Go (n番煎じ)

Last updated at Posted at 2016-03-11

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("キ・ヨ・シ!")
}
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6