mirror of
https://github.com/flancian/garden.git
synced 2026-08-07 15:06:19 +00:00
autopushed
This commit is contained in:
+5
-6
@@ -22,9 +22,9 @@ def echo_sieve(sieve):
|
|||||||
click.echo(f"[[{n}]] is prime.")
|
click.echo(f"[[{n}]] is prime.")
|
||||||
|
|
||||||
def is_prime(n):
|
def is_prime(n):
|
||||||
sieve = [True for n in range(0, n+1)]
|
SIEVE = [True for n in range(0, n+1)]
|
||||||
upto = math.ceil(math.sqrt(n))
|
upto = math.ceil(math.sqrt(n))
|
||||||
for i, _ in enumerate(sieve):
|
for i, _ in enumerate(SIEVE):
|
||||||
# click.echo(f"i: {i}")
|
# click.echo(f"i: {i}")
|
||||||
if i < 2:
|
if i < 2:
|
||||||
continue
|
continue
|
||||||
@@ -32,7 +32,7 @@ def is_prime(n):
|
|||||||
if i > upto:
|
if i > upto:
|
||||||
break
|
break
|
||||||
# If this is a known composite, then we've already crossed off its multiples when we iterated over its primes.
|
# If this is a known composite, then we've already crossed off its multiples when we iterated over its primes.
|
||||||
if not sieve[i]:
|
if not SIEVE[i]:
|
||||||
continue
|
continue
|
||||||
# for j in range(2, math.ceil(math.sqrt(n) + 1)):
|
# for j in range(2, math.ceil(math.sqrt(n) + 1)):
|
||||||
for j in range(2, n):
|
for j in range(2, n):
|
||||||
@@ -41,11 +41,10 @@ def is_prime(n):
|
|||||||
break
|
break
|
||||||
PROOF.append(f"[[{i*j}]] is composite: {i} * {j}.")
|
PROOF.append(f"[[{i*j}]] is composite: {i} * {j}.")
|
||||||
try:
|
try:
|
||||||
sieve[i*j] = False
|
SIEVE[i*j] = False
|
||||||
except IndexError:
|
except IndexError:
|
||||||
continue
|
continue
|
||||||
# echo_sieve(sieve)
|
return n >= 2 and SIEVE[n]
|
||||||
return n >= 2 and sieve[n]
|
|
||||||
|
|
||||||
class AgoraCmd(click.Command):
|
class AgoraCmd(click.Command):
|
||||||
def format_help(self, ctx, formatter):
|
def format_help(self, ctx, formatter):
|
||||||
|
|||||||
Reference in New Issue
Block a user