4 Commits

Author SHA1 Message Date
34980ed0b4 Solve problem 2020-10-12 22:20:47 +02:00
d770dd831e Complete problem 2020-10-12 21:49:31 +02:00
ddc4943f57 Solve task 2020-10-12 20:39:14 +02:00
20933b4f16 Complete task 2020-10-12 20:02:04 +02:00
4 changed files with 58 additions and 54 deletions

View File

@@ -1,10 +1,7 @@
import math
from functools import reduce
def factors(x):
result = [1]
i = 2
while i*i <= x: #Other way of writing i<=sqrt(x)
while i*i <= x:
if x % i == 0:
result.append(i)
if x//i != i:
@@ -12,39 +9,18 @@ def factors(x):
i += 1
return result
def is_abundant(n):
return sum(factors(n)) > n
def isAbundant(x):
return sum(factors(x)) > x
abundants= [i for i in range(28123) if is_abundant(i)]
abundantNumbers = [num for num in range(1, 28123) if isAbundant(num)]
sums = [True for _ in range(1,28123)]
range28 = [range(28123+1)]
abundantsums = []
result = []
for i in range(len(abundants)):
for j in range(len(abundants)-i):
if abundants[i]+abundants[i-j]<=28123 and abundants[i]+abundants[i-j] in range28:
abundantsums.append(abundants[i]+abundants[i-j])
range28.pop(range28.index(abundants[i]+abundants[i-j]))
result.append(abundants[i]+abundants[i-j])
print(len(abundantsums)) #24 266 061
print("calculated abundantsums")
for i in range(len(abundantNumbers)):
for k in range(len(abundantNumbers)):
try:
sums[abundantNumbers[i] + abundantNumbers[k]] = False
except IndexError:
pass
#result = sum([i for i in range(28123+1) if not i in abundantsums])
# result = 0
# for i in range(28123+1):
# print(i)
# if not i in abundantsums:
# result+=i
# range28 = [range(28123+1)]
# result = []
# for i in abundantsums:
# if i in range28:
# range28.pop(range28.index(i))
# result.append(i)
print(result)
print(sum([i for i, x in enumerate(sums) if x]))

View File

@@ -1,4 +1,16 @@
for i in range(1,1000):
x = 1/i
numsWithRecurringCycles = [n for n in range(2,1000) if n % 2 != 0 and n % 5 != 0]
def digits(num, divisor):
x = num
storedSums = []
while not x*10 in storedSums:
x *= 10
storedSums.append(x)
x %= divisor
return len(storedSums)
digitNumList = [digits(1, n) for n in numsWithRecurringCycles]
print(numsWithRecurringCycles[digitNumList.index(max(digitNumList))])

View File

@@ -1,16 +1,14 @@
totalSum=0
usedFactors = []
for i in range(1, 10000):
if i%100==0:
print(str(i/100) + "%")
for j in range(1, 10000):
x=i*j
if len(str(i))+len(str(j))+len(str(x))==9:
result = sum([int(k) for k in str(x)])
result += sum([int(k) for k in str(i)])
result += sum([int(k) for k in str(j)])
if sum==1+2+3+4+5+6+7+8+9:
totalSum+=x
from itertools import permutations
from math import ceil
print(totalSum)
#HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
def isPanDigital(i,j,x):
return sorted(str(i) + str(j) + str(x)) == ['1' ,'2', '3', '4', '5', '6', '7', '8', '9']
panDigits = []
for i in range(1,10000):
for j in range(1,ceil(10000/i)):
prod = i*j
if isPanDigital(i, j, prod) and not prod in panDigits:
panDigits.append(prod)
print(sum(panDigits))

View File

@@ -0,0 +1,18 @@
def has5Permutations(n):
return numberList[len(n)].count(n) == 5
numberList = [[] for _ in range(100)]
i=1
while True:
n = i**3
sortedN = ''.join(sorted(str(n)))
numberList[len(sortedN)].append(sortedN)
if has5Permutations(sortedN):
index = numberList[len(sortedN)].index(sortedN)
print((sum([len(numberList[j]) for j in range(len(sortedN)) ]) + index+1) ** 3)
exit(0)
i += 1