Created
August 12, 2012 08:15
-
-
Save alterakey/3330622 to your computer and use it in GitHub Desktop.
Enrico Pucci on Primes
This file contains hidden or 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
class Sieve { | |
def mLimit = 0; | |
def mNonPrimes = [] as Set | |
def mPrimes = [] as Set | |
def Sieve(limit) { | |
mLimit = limit; | |
} | |
def find() { | |
for (i in 2..mLimit+1) { | |
if (i in mNonPrimes) | |
continue | |
_markSeries(i) | |
mPrimes << i | |
} | |
return mPrimes | |
} | |
def _markSeries(base) { | |
def p = base | |
while (p <= mLimit) { | |
p = p + base | |
mNonPrimes << p | |
} | |
} | |
} | |
class Enrico { | |
def mUnder = 100 | |
def Enrico(under) { | |
mUnder = under | |
} | |
def find() { | |
def primes = new Sieve(mUnder).find() | |
(1..mUnder).each { i -> | |
if (i in primes) | |
println "Enrico Pucci" | |
else | |
println i | |
} | |
} | |
} | |
new Enrico(100).find() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment