Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 34980ed0b4 | |||
| d770dd831e | |||
| ddc4943f57 | |||
| 20933b4f16 |
@@ -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]))
|
||||
|
||||
|
||||
@@ -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))])
|
||||
|
||||
@@ -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))
|
||||
18
src/task62 - Cubic permutations.py
Normal file
18
src/task62 - Cubic permutations.py
Normal 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
|
||||
Reference in New Issue
Block a user