Skip to content

Instantly share code, notes, and snippets.

@mapedd
Created January 29, 2015 15:45
Show Gist options
  • Save mapedd/d4c04a5d965a0bf1203e to your computer and use it in GitHub Desktop.
Save mapedd/d4c04a5d965a0bf1203e to your computer and use it in GitHub Desktop.
Why does this crash?
import Foundation
func eratosthenes(n: Int) -> [Int]{
var results = [Int]()
for i in 0...(n-1){
results.append(i+1)
}
for i in 0...(n-1){
var number = results[i]
var divides = number % i == 0
if (divides) {
results[i] = -1
}
println(number)
}
return results
}
eratosthenes(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment