Skip to content

Instantly share code, notes, and snippets.

@el-hoshino
Created March 12, 2016 13:23
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 el-hoshino/53eaded008ee617cf6d1 to your computer and use it in GitHub Desktop.
Save el-hoshino/53eaded008ee617cf6d1 to your computer and use it in GitHub Desktop.
ズンドコキヨシ with Swift ref: http://qiita.com/lovee/items/1bfc190a8a221cc6b01c
import Foundation
let candidates = ["ガルパン", "は", "いい", "ぞ"]
var createdPhrase = [String](count: candidates.count, repeatedValue: "")
for i in 0 ..< Int.max {
if createdPhrase != candidates {
let randomNumber = Int(arc4random_uniform(UInt32(candidates.count)))
let nextWord = candidates[randomNumber]
print(nextWord)
createdPhrase.removeFirst()
createdPhrase.append(nextWord)
} else {
print("\(i) times")
break
}
}
print(createdPhrase.reduce("", combine: {$0 + $1}) + "!")
//前略
ガルパン
ガルパン
いい
いい
ガルパン
ガルパン
ガルパン
いい
ガルパン
いい
462 times
ガルパンはいいぞ!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment