Improve code

This commit is contained in:
2019-09-28 11:32:21 +02:00
parent 7489196be8
commit ec1d1fa446
8 changed files with 16 additions and 26 deletions

View File

@ -26,7 +26,7 @@ def max_prime_factor(num):
# If num is divisible by i and i is prime, find largest
# prime factor of num/i.
while 1:
while True:
if num % i == 0:
if is_prime(i):
return max_prime_factor(num//i)

View File

@ -33,7 +33,7 @@ def main():
n = 0
j = 1
while 1:
while True:
tmp = i * j
n = n + tmp
j = j + 1

View File

@ -8,15 +8,6 @@
from timeit import default_timer
from projecteuler import is_pandigital, is_prime
def count_digits(n):
i = 0
while n > 0:
i = i + 1
n = n // 10
return i
def main():
start = default_timer()
@ -28,7 +19,7 @@ def main():
i = 7654321
while(i > 0):
if is_pandigital(i, count_digits(i)) and is_prime(i):
if is_pandigital(i, len(str(i))) and is_prime(i):
break
# Skipping the even numbers.
i = i - 2

View File

@ -35,7 +35,7 @@ def main():
i = 1
# Brute force approach, try every integer number until the desired one is found.
while 1:
while True:
if have_same_digits(i, 2*i) and have_same_digits(i, 3*i) and have_same_digits(i, 4*i) and\
have_same_digits(i, 5*i) and have_same_digits(i, 6*i):
break

View File

@ -18,15 +18,6 @@
from timeit import default_timer
def count_digits(n):
count = 0
while n > 0:
n = n // 10
count = count + 1
return count
def main():
start = default_timer()
@ -41,7 +32,7 @@ def main():
d = n + d
n = n + d2
if count_digits(n) > count_digits(d):
if len(str(n)) > len(str(d)):
count = count + 1
end = default_timer()

View File

@ -33,7 +33,7 @@ def main():
count = 0
diag = 5
while 1:
while True:
i = i + step
if is_prime(i):