Skip to content

Instantly share code, notes, and snippets.

View voith's full-sized avatar
👨‍🎓
Building on top of Ethereum

Voith voith

👨‍🎓
Building on top of Ethereum
View GitHub Profile
@voith
voith / sum_amicable.py
Created November 5, 2019 16:40
sum of all the amicable numbers under 10000
from math import sqrt
def _sum_of_proper_divisors(n, sum_of_proper_divisors):
_sum = 1
sqrt_n = int(sqrt(n))
for i in range(2, sqrt_n+1):
if n % i == 0:
_sum += i
if n // i != i:
_sum += n // i
@voith
voith / sum_of_2_non_abundant.py
Created November 10, 2019 00:49
sum of all the positive integers which cannot be written as the sum of two abundant numbers.
from math import sqrt
def sum_of_divisors(number):
_sum = 1
nsqrt = int(sqrt(number))
for i in range(2, nsqrt + 1):
if number % i == 0:
_sum += i
if (number / i != nsqrt):
@voith
voith / nth_lexographic_permutation.py
Last active November 12, 2019 04:20
millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9
from math import factorial
numbers = list(range(10))
nth_perm = 1000000
total_numbers = len(numbers)
num = ''
def get_factorial_divisor(factorial, dividend):
@voith
voith / reciprocal_cycles.py
Created November 12, 2019 03:59
value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction par
largest_num = 1000
largest_divisor = 3
longest_cycle = 1
rdigits = ''
def get_divide_result(i):
seen_remainders = [False] * i
remainder = 10 % i
cycle_count = 0
while remainder!= 0 and seen_remainders[remainder] is False:
@voith
voith / quadratic_primes.py
Created November 16, 2019 19:38
Find the product of the coefficients, a and b, for the quadratic expression (n**2+n+41) that produces the maximum number of primes for consecutive values of n, starting with n=0.
from math import sqrt
MAX = 999999
sieve = [True] * (MAX + 1)
sieve[0], sieve[1] = False, False
for i in range(2, int(sqrt(MAX)) + 1):
if sieve[i] is True:
for j in range(2 * i, MAX, i):
@voith
voith / sum_spiral_diagonals.py
Created November 28, 2019 02:42
sum of the numbers on the diagonals in a 1001 by 1001 spiral
grid_size = 1001
num = grid_size ** 2
sum_diagonals = num
for i in range(grid_size - 1, 0, -2):
for _ in range(4):
num -= i
sum_diagonals += num
print(sum_diagonals)
@voith
voith / coin_change.py
Last active November 30, 2019 18:52
Findall possible ways €2 can be split using coins 1p, 2p, 5p, 10p, 20p, 50p, €1 (100p) and €2 (200p)
final_target = 200
possibilities = [0] * (final_target + 1)
possibilities[0] = 1
# keeping the coins sorted is the key here
# we want to compute possibilities for lower coins first.
# This helps us to fix one particular coin and
# then find the other possibilites of the change needed
coins = [1, 2, 5, 10, 20, 50, 100, 200]
for coin in coins:
for current_target in range(coin, final_target + 1):
@voith
voith / grid_dfs.py
Created December 13, 2019 18:22
total number of connected regions in a grid
class Solution(object):
def __init__(self, matrix, row, col):
self.matrix = matrix
self.row = row
self.col = col
def is_safe(self, i, j, visited):
return (
0 <= i < self.row and
def get_all_substrings(arr, index, subarr, record):
if index == len(arr):
if len(subarr) != 0:
record.append(''.join(subarr))
else:
get_all_substrings(arr, index + 1, subarr, record)
get_all_substrings(arr, index + 1, subarr + [arr[index]], record)
return record
[{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"internalType": "string",