import Foundation
import UIKit
class Recursion: NSObject {
internal var zundoko = [String]()
internal var item: [String]!
internal var decision: String!
internal var count: Int!
internal var resultNumber = 0
override init() {
super.init()
}
convenience init(itemArray: [String], decisionStr: String, maxCount: Int) {
self.init()
item = itemArray
result = resultStr
decision = decisionStr
count = maxCount
}
func recursionZunDoko() -> Bool {
zundoko.append(getZundoko())
resultNumber += 1
if checkZundoko() {
return true
} else {
return recursionZunDoko()
}
}
internal func getZundoko() -> String {
let random = arc4random_uniform(UInt32(item.count))
return item[Int(random)]
}
internal func checkZundoko() -> Bool {
if zundoko.count > count {
zundoko.removeFirst()
}
let str = zundoko.reduce("", combine: +)
if str == decision {
return true
} else {
return false
}
}
}