Skip to content

Instantly share code, notes, and snippets.

@alterakey
Created August 12, 2012 08:15
Show Gist options
  • Save alterakey/3330622 to your computer and use it in GitHub Desktop.
Save alterakey/3330622 to your computer and use it in GitHub Desktop.
Enrico Pucci on Primes
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