This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#x % 10 will be the first digit, then we x // 10 to remove it and repeat | |
def sum_digits(x): | |
totalsum = 0 | |
while x != 0: | |
totalsum += x % 10 | |
x = x // 10 | |
return totalsum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Divisors(x): | |
divisors = [] | |
for i in range(1, int(math.sqrt(x)) + 1): | |
if x % i == 0: | |
divisors.append(i) | |
divisors.append(int(x/i)) | |
divisors.remove(x) #Remove this line if you want to include x as a divisor of x | |
return (divisors) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def continued_fraction(x): | |
m0 = 0 | |
d0 = 1 | |
a0 = math.floor(math.sqrt(x)) #These are the starting values | |
temp_list = [a0] | |
while True: | |
mn = int(d0*a0 - m0) | |
dn = int((x - mn**2)/d0) | |
an = int(math.floor((math.sqrt(x) + mn) / dn)) #new values | |
temp_list.append(an) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Partition(goal, alist): | |
ways = [0] + [1] * (goal) | |
for options in alist: | |
for i in range(len(ways) - options): | |
ways[i + options] += ways[i] | |
return ways[-1] #-1 here if you don't want to include 4 + 0 as a partition of 4 for example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ppt(limit): | |
triples = [] | |
for m in range(2,int(math.sqrt(limit))+1): | |
for n in range(1,m): | |
if (m+n) % 2 == 1 and math.gcd(m,n) == 1: | |
a = m**2 + n**2 | |
b = m**2 - n**2 | |
c = 2*m*n | |
p = max(a,b,c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Divisors(x): | |
divisors = [] | |
for i in range(1,int(math.sqrt(x))+1): | |
if x % i == 0: | |
divisors.append(i) | |
if i != int(x/i): | |
divisors.append(int(x/i)) | |
divisors.remove(x) | |
return sum(set(divisors)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These are the fifth power digit sum numbers except the last one is missing | |
#[4150, 4151, 54748, 92727, 93084] | |
def sum_digits_mod(x): | |
totalsum = 0 | |
while x != 0: | |
totalsum += (x % 10)**5 | |
x = x // 10 | |
return totalsum | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute(): | |
totalways = 1 | |
for a in range(0,3): | |
for b in range(0,(2-a)*2 + 1): | |
for c in range(0,math.ceil((2-a-b*0.5)*10)+1): | |
for d in range(0,math.ceil((2-a-b*0.5-c*0.2)*20)+1): | |
for e in range(0,math.ceil((2-a-b*0.5-c*0.2-d*0.1)*40)+1): | |
for f in range(0,math.ceil((2-a-b*0.5-c*0.2-d*0.1-e*0.05)*100)+1): | |
for g in range(0,math.ceil((2-a-b*0.5-c*0.2-d*0.1-e*0.05-f*0.02)*200)+1): | |
if a*100 + b*50 + c*20 + d*10 + e*5 + f*2 + g*1 == 200: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute(): | |
testlist = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] | |
values = set() | |
for x in range(9,99): | |
for y in range(99,999): | |
answer = x*y | |
if answer < 10000: | |
testingvalue = sorted(str(x) + str(y) + str(answer)) | |
if testingvalue == testlist: | |
values.add(answer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute(): | |
values = [] | |
numer = 1 | |
denom = 1 | |
for x in range(10,100): | |
for y in range(x+1, 100): | |
if x%10 != 0 and y%10 != 0: | |
value1 = str(x) | |
value2 = str(y) | |
for a in value1: |