Created
January 29, 2015 15:45
-
-
Save mapedd/d4c04a5d965a0bf1203e to your computer and use it in GitHub Desktop.
Why does this crash?
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
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