Skip to content

Instantly share code, notes, and snippets.

@mknudsen
Created September 22, 2014 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mknudsen/aefab6ed575eb72c003c to your computer and use it in GitHub Desktop.
Save mknudsen/aefab6ed575eb72c003c to your computer and use it in GitHub Desktop.
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