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 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
| 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 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 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 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
| #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 numberToBase(n, b): | |
| if n == 0: | |
| return [0] | |
| digits = [] | |
| while n != 0: | |
| digits.append(int(n % b)) | |
| n //= b | |
| return digits[::-1] |
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 fibonnaci(n): #Finds the nth fibonnaci number | |
| v1, v2, v3 = 1, 1, 0 # initialise a matrix [[1,1],[1,0]] | |
| for rec in bin(n)[3:]: # perform fast exponentiation of the matrix (quickly raise it to the nth power) | |
| calc = v2*v2 | |
| v1, v2, v3 = v1*v1+calc, (v1+v3)*v2, calc+v3*v3 | |
| if rec=='1': | |
| v1, v2, v3 = v1+v2, v1, v2 | |
| return v2 |
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 is_prime(x): | |
| if x <= 1: | |
| return False | |
| elif x <= 3: | |
| return True | |
| elif x % 2 == 0: | |
| return False | |
| else: | |
| for i in range(3, int(math.sqrt(x)) + 1, 2): | |
| if x % i == 0: |