Created
January 29, 2015 16:18
-
-
Save mapedd/25fc76480c8379398991 to your computer and use it in GitHub Desktop.
Stop dividing by 0
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
// Playground - noun: a place where people can play | |
import Cocoa | |
func eratosthenes(n: Int) -> [Int]{ | |
var results = Array(1...n) | |
for i in 1...(n-1){ | |
var number = results[i] | |
if (number % i == 0) { | |
results[i] = -1 | |
} | |
} | |
return results | |
} | |
eratosthenes(10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment