Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@igorvanloo
igorvanloo / admissible_numbers.py
Last active March 24, 2022 16:53
admissible numbers
def admissible_numbers(p, n, primes, limit):
a_n = [n] #admissible numbers
i = primes.index(p) #index
if n > limit:
return []
a_n += admissible_numbers(p, n*p, primes, limit)
if i + 1 < len(primes):
n_p = primes[i + 1] #next prime
a_n += admissible_numbers(n_p, n*n_p, primes, limit)
return a_n
@igorvanloo
igorvanloo / k_smooth_numbers.py
Created March 12, 2022 16:15
k_smooth_numbers
def k_smooth_numbers(max_prime, limit):
k_s_n = [1]
p = list_primes(max_prime)
while len(p) != 0:
temp_k_s_n = []
curr_p = p.pop(0)
power_limit = int(math.log(limit, curr_p)) + 1
curr_multiples = [curr_p**x for x in range(1, power_limit + 1)]
for x in curr_multiples:
for y in k_s_n:
def sum_decimals(num, den):
num_digits = 0
digit_sum = 0
while True:
num *= 10
temp = math.floor(num/den)
digit_sum += temp
num_digits += 1
num -= temp*den
if num == 1:
@igorvanloo
igorvanloo / p348.py
Created December 17, 2021 03:57
Problem 348
def compute():
total = 0
array = dict()
for cb in range(2, int(10**(9/3)) + 1):
for sq in range(2, int(10**(4.5)) + 1):
t = cb*cb*cb + sq*sq
if str(t) == str(t)[::-1]:
if t in array:
array[t] += 1
else:
@igorvanloo
igorvanloo / primecounting.py
Created December 16, 2021 04:48
Prime Counting Function
def primepi(limit):
def Prime_sieve(n): #Sieve of Eratosthenes
result = [True] * (n + 1)
result[0] = result[1] = False
for i in range(int(math.sqrt(n)) + 1):
if result[i]:
for j in range(2 * i, len(result), i):
result[j] = False
return result
@igorvanloo
igorvanloo / mobius.py
Created December 16, 2021 04:45
Möbius function
def Mobius(n):
if n == 1:
return 1
d = 2
num_of_primes = 0
while n > 1:
while n % d == 0:
num_of_primes += 1
if n % (d*d) == 0:
return 0
@igorvanloo
igorvanloo / phi.py
Created December 16, 2021 04:43
Euler Totient Function
def phi(n):
if n == 1:
return 1
phi = 1
d = 2
while n > 1:
count = 0
while n % d == 0:
count += 1
n /= d
@igorvanloo
igorvanloo / lcm.py
Created December 11, 2021 11:22
LCM Function
def lcm(numbers):
n = sorted(numbers) #I want to start with the largest numbers
curr = n.pop(-1) #Remove the biggest
while len(n) != 0:
temp = n.pop(-1)
curr = int(abs(curr*temp)/math.gcd(curr, temp)) #Continuously find the lcm between the 2 largest numbers
return curr
@igorvanloo
igorvanloo / p491.py
Created December 9, 2021 05:56
p491
import itertools
def number_of_doubles(pand):
doubles = 0
for x in range(0,10):
if pand.count(str(x)) == 2:
doubles += 1
return doubles
def compute():
@igorvanloo
igorvanloo / p150.py
Created December 6, 2021 10:19
p150
def triangle_generator():
t = 0
s = []
for k in range(1,500501):
t = (615949*t + 797807) % 2**20
s.append(t - 2**19)
#First I generate the s values
triangle = []
r = 1000
while r != 0: