Remove file
This commit is contained in:
parent
04ea549223
commit
5af2692816
@ -1,48 +0,0 @@
|
||||
import math
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def timeit(name):
|
||||
def profile(original):
|
||||
import time
|
||||
@wraps(original)
|
||||
def wrapper(*args, **kwargs):
|
||||
t0 = time.perf_counter()
|
||||
result = original(*args, **kwargs)
|
||||
t1 = time.perf_counter()
|
||||
print(f"Time to evaluate problem {int(name[7:]):003d}: {(t1 - t0)*1000:.3f} ms\n")
|
||||
return result
|
||||
return wrapper
|
||||
return profile
|
||||
|
||||
|
||||
def is_prime(n):
|
||||
if n <2:
|
||||
return False
|
||||
for i in range(2, int(math.sqrt(n)) + 1):
|
||||
if n % i == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# Returns a list of True and False indicating whether each number is prime.
|
||||
# For 0 <= i <= n, result[i] is True if i is a prime number, False otherwise.
|
||||
def list_primality(n):
|
||||
# Sieve of Eratosthenes
|
||||
result = [True] * (n + 1)
|
||||
result[0] = result[1] = False
|
||||
for i in range(int(math.sqrt(n) + 1)):
|
||||
if result[i]:
|
||||
for j in range(i * i, len(result), i):
|
||||
result[j] = False
|
||||
return result
|
||||
|
||||
|
||||
# Returns all the prime numbers less than or equal to n, in ascending order
|
||||
# For example: list_primes(97) = [2, 3, 5, 7, 11, ..., 83, 89, 97].
|
||||
def list_primes(n):
|
||||
return [i for (i, is_prime) in enumerate(list_primality(n)) if is_prime]
|
||||
|
||||
|
||||
def is_palindrome(num):
|
||||
return str(num) == str(num)[::-1]
|
Loading…
x
Reference in New Issue
Block a user