Skip to content

Instantly share code, notes, and snippets.

@luckyriverr
Last active March 21, 2016 02:13
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 luckyriverr/ec897480e25ede194378 to your computer and use it in GitHub Desktop.
Save luckyriverr/ec897480e25ede194378 to your computer and use it in GitHub Desktop.
春のズンドコ祭り Ruby vs Golang ref: http://qiita.com/luckyriver0/items/296db692c65c179d147c
package main
import (
"fmt"
"math/rand"
"os"
"reflect"
"time"
)
func main() {
zun := "ズン"
doko := "ドコ"
answer := []string{zun, zun, zun, zun, doko}
zundoko := []string{zun, doko}
q := []string{}
for {
q = append(q, choice(zundoko))
if len(q) >= len(answer) {
say := q[len(q)-len(answer):]
fmt.Println(say)
sayKiyoshi(say, answer)
q = say
}
}
}
func choice(list []string) string {
rand.Seed(time.Now().UnixNano())
i := rand.Intn(len(list))
return list[i]
}
func sayKiyoshi(say []string, answer []string) {
if reflect.DeepEqual(say, answer) {
fmt.Println("キ・ヨ・シ!")
os.Exit(0)
}
}
zds = []
loop.lazy.map{ ['ズン', 'ドコ'].sample }.each do |zd|
print zd
zds << zd
break if zds.last(5) == ["ズン", "ズン", "ズン", "ズン", "ドコ"]
end
print " キ・ヨ・シ!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment