Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@igorvanloo
igorvanloo / p34.py
Created July 23, 2021 06:01
Problem 34
def sum_digits_mod(x):
facts = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
totalsum = 0
while x != 0:
totalsum += facts[x % 10]
x = x // 10
return totalsum
def compute():
overalltotal = 0
@igorvanloo
igorvanloo / p38.py
Created July 23, 2021 11:14
Problem 38
def compute():
checker = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
concatenated_product_list = []
for z in range(2,10):
for x in range(1,10**math.floor(9/z)):
temp_str = ""
for y in range(1,z+1):
product = x*y
temp_str += str(product)
if sorted(temp_str) == checker:
@igorvanloo
igorvanloo / p42.py
Created July 24, 2021 06:24
Problem 42
Triangle_number = [ "the triangle numbers from the txt file" ]
def sumofname(x):
namesum = 0
for i in range(len(words[x])):
namesum += ord(words[x][i])-64
return namesum
def compute():
count = 0
@igorvanloo
igorvanloo / p44.py
Created July 24, 2021 07:02
Problem 44
def is_pentagonal(x):
#Take the inverse function to test whether or not a number is pentagonal
if (1+(24*x+1)**0.5) % 6 == 0:
return True
return False
def compute():
k = 1
while True:
for j in range(1,k): # this ensures that a > b therefore a-b is minimised
@igorvanloo
igorvanloo / p45.py
Created July 24, 2021 07:11
Problem 45
def is_pentagonal(x):
#Take the inverse function to test whether or not a number is pentagonal
if (1+(24*x+1)**0.5) % 6 == 0:
return True
return False
def is_hexagonal(x):
#Take the inverse function to test whether or not a number is hexagonal
if (1+(8*x+1)**0.5) % 4 == 0:
return True
@igorvanloo
igorvanloo / p79.py
Created July 24, 2021 13:23
Problem 79
def all_numbers(alist):
nums = set()
for x in alist:
for y in x:
nums.add(y)
return list(nums)
def method1():
possible_numbers = (all_numbers(keys))
possible_passcode = list(itertools.permutations(possible_numbers))
@igorvanloo
igorvanloo / p46.py
Created July 25, 2021 03:34
Problem 46
def goldbachs(number):
for x in range(1, int(math.sqrt(number))+1):
temp_var = number - 2*(x**2)
if is_prime(temp_var) == True:
return True
return False
def compute():
count = 33
while True:
@igorvanloo
igorvanloo / p47.py
Last active July 25, 2021 05:20
Problem 47
def list_primality_modified(n):
result = [0] * (n + 1) #Initialize an array of length n+1
for i in range(2,int((n)) + 1): #We want to go all the way to the length instead of sqrt(n)
#to include all prime factors
if result[i] == 0: #If this value has not been marked yet, continue
for j in range(2 * i, len(result), i):
result[j] += 1 #Add all the prime factors
return result
#We will obtain a list where array[x] represents the number of prime factors of x,
#if array[x] = 0 then x is a prime
@igorvanloo
igorvanloo / p49.py
Created July 25, 2021 04:52
Problem 49
def compute():
primes = sorted(list(set(list_primes(10000)) - set((list_primes(1000)))))
supercandidates = []
while len(primes) != 0:
curr = primes.pop()
candidates = [curr]
for y in primes:
if sorted(str(curr)) == sorted(str(y)):
candidates.append(y)
@igorvanloo
igorvanloo / p52.py
Created July 25, 2021 08:01
Problem 52
def compute():
x = 100
while True:
count = 1
for i in range(2, 7):
if sorted(str(x)) != sorted(str(i*x)):
break
count += 1
if count == 6:
return x