Int(stringValue)
. Правда, вам это не сильно поможет - есть ещё косяки. Можете попытаться исправить их самостоятельно.func worthSum(count: String, worth: [Int]) -> Int {
return count.split(separator: " ").enumerated().reduce(0, { acc, n in
acc + (Int(n.1) ?? 0) * worth[n.0]
})
}
func evaluate(good: String, vsEvil evil: String) -> String {
let g = worthSum(count: good, worth: [ 1, 2, 3, 3, 4, 10 ])
let e = worthSum(count: evil, worth: [ 1, 2, 2, 2, 3, 5, 10 ])
return g == e
? "Battle Result: No victor on this battle field"
: g > e
? "Battle Result: Good triumphs over Evil"
: "Battle Result: Evil eradicates all trace of Good"
}
fibbonachi(n[0],left+n[1])
fibbonachi(n[1], left + n[1])
let arrays: [[String]] = [array1, array2]
var combinations: [[String]] = []
let arraysLen: Int = arrays.count
let arrLen: Int = arrays[0].count
let numCombinations: Int = Int(pow(Double(arraysLen), Double(arrLen)))
for i in (0 ..< numCombinations) {
var combination: [String] = []
for j in (0 ..< arrLen) {
let arrIndex: Int = i / Int(pow(Double(arraysLen), Double(j))) % arraysLen
let elIndex: Int = arrLen - j - 1
combination.insert(arrays[arrIndex][elIndex], at: 0)
}
combinations.append(combination)
}