Skip to content

Instantly share code, notes, and snippets.

@mapedd
Created January 29, 2015 16:18
Show Gist options
  • Save mapedd/25fc76480c8379398991 to your computer and use it in GitHub Desktop.
Save mapedd/25fc76480c8379398991 to your computer and use it in GitHub Desktop.
Stop dividing by 0
// 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