Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for The Best Number Ever by han97
# migrated from python 2.7
from functools import reduce
def checkio():
assert add_up_primes(71)
assert is_prime(71) and is_prime(17) # a permutable prime with 17.
assert is_prime(73) and is_prime(71) # the 20th prime number. The next is 73, with which it composes a twin prime.
assert 71 ** 2 == factorial(7) + 1 # part of the last known pair (71, 7) of Brown numbers, since 71^2 = 7! + 1.
return 71
def factorial(num):
return reduce(lambda x, y: x * y, range(1, num + 1), 1)
def is_prime(num):
for i in range(2, int(num ** 0.5 + 1)):
if num % i == 0:
return False
return True
def add_up_primes(num):
"""If we add up the primes less than 71 (2 through 67),
we get 568, which is divisible by 71, 8 times."""
return sum(sieve_of_eratosthenes(num)) / num == 8
def sieve_of_eratosthenes(number):
lst = [True] * number
i = 2
while True:
if i ** 2 > number:
break
while i < number and not lst[i]:
i += 1
for x in range(i ** 2, number, i):
lst[x] = False
i += 1
return [i for i, x in enumerate(lst) if x and (i != 1 and i)]
July 15, 2016
Comments: