Last active
March 21, 2016 02:13
-
-
Save luckyriverr/ec897480e25ede194378 to your computer and use it in GitHub Desktop.
春のズンドコ祭り Ruby vs Golang ref: http://qiita.com/luckyriver0/items/296db692c65c179d147c
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" | |
"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) | |
} | |
} |
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
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