Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
func recursiveAdder(list:[Int]) -> Int {
switch list.count {
case 0:
return 0
case 1:
return list.first!
case 2:
return list.first! + list.last!
default:
let firstTwo:[Int] = [list.first! + list[1]]
let rest = list[2...list.count-1]
return recursiveAdder(firstTwo + rest)
}
}
let numbers = 1...9000
let result = recursiveAdder(numbers.map { $0 } )
println(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment