Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The best Number solution in Creative category for The Best Number Ever by tanya
def primes_method(n):
counter=1
for num in range(3, n+1, 2):
if all(num % i != 0 for i in range(2, int(num**.5 ) + 1)):
counter+=1
return counter
def isprime(n):
return n == 2 or n > 2 and n%2 != 0 and all(n%i for i in range(3, int(n**0.5)+1, 2))
def sum_digit(n):
return (sum(int(x) for x in str(n)))
def reduce_digit(n):
p = 1
for i in str(n):
p *= int(i)
return p
def Pythagoras_number(n):
counter=1
while True:
x=4*counter+1
if x==n:
return counter
counter+=1
if x>n:
return False
def twin_prime(n,m):
counter=1
while True:
x=6*counter-1
y=6*counter+1
if x==n and y==m and n+2==m:
if isprime(n) and isprime(m):
return True
counter+=1
if x>n:
return False
def Sophie_Germain_prime(n):
counter=1
x=2
while True:
if isprime(x) and isprime(2*x+1):
counter+=1
if x==n:
return counter
x+=1
if x>n:
return False
def Consecutive_numbers(n):
for i in range(n//3):
s=i**2
for j in range(i+1,n//3):
j**=2
s+=j
if s==n:
return True
return False
def checkio():
n=29
sum_digit(n)+reduce_digit(n)==n # the number is equal to the sum of the sum
# of its digits and the production of its digits
n+int(str(n)[::-1])==pow(sum_digit(n),2) #the sum of the number of the same number reverted
#is equal to the square of the sum od its digits
Consecutive_numbers(n) #the sum of three consecutive squares
if isprime(n):
primes_method(n) # tenth prime
isprime(sum_digit(n)) # the sum of digits is a prime number 11
Pythagoras_number(n) # seventh prime Pythagoras number
twin_prime(n,n+2) # twin prime pair with thirty-one
Sophie_Germain_prime(n) # sixth Sophie Germain prime
return n
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert isinstance(checkio(), (int, float, complex))
Feb. 7, 2019
Comments: