This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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