Skip to content

Instantly share code, notes, and snippets.

@yutailang0119
Last active December 31, 2017 14:55
Show Gist options
  • Save yutailang0119/130ab77ce755423ca5538181cf2b4485 to your computer and use it in GitHub Desktop.
Save yutailang0119/130ab77ce755423ca5538181cf2b4485 to your computer and use it in GitHub Desktop.
import Foundation
enum Phrase: Int, CustomStringConvertible {
case zun = 0
case doko = 1
var description: String {
switch self {
case .zun:
return "ずん"
case .doko:
return "どこ"
}
}
}
func kiyoshiNoZundokoBushi() {
for _ in 0..<INT_MAX {
let phrases: [Phrase] = Array(0..<5).flatMap({ _ in Phrase(rawValue: Int(arc4random_uniform(2))) })
let string: String = phrases.reduce("", { (result, phrase) in
return result + phrase.description
})
if phrases == [.zun, .zun, .zun, .zun, .doko] {
print(string + "きよし!")
break
} else {
print(string)
}
}
}
kiyoshiNoZundokoBushi()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment