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 / withdraw.sol
Last active January 13, 2022 19:27
Sample solidity function
pragma solidity ^0.5.16;
contract DummyERC20 is ERC20 {
function withdraw() external {
uint256 amount = balances[msg.sender];
// demo reentracy
require(msg.sender.call.value(amount)());
balances[msg.sender] = 0;
}
pps = [
'1-5 k: kkkkhkkkkkkkkkk',
'5-7 k: blkqhtxfgktdkxzkksk',
'15-16 x: xxxxxxxxxxxxxxlf',
'3-5 j: fjpvj',
'17-20 x: zsxjrxkgxxxxxxxmxgxf',
'5-6 m: swjzmmmlx',
'2-4 v: vqdn',
'8-12 t: thllsbqtgdsf',
'10-17 h: vpbrjcbhnwqhhphxjk',
@voith
voith / evm_add.py
Created October 19, 2020 12:58
Example to add two numbers using the Ethereum virtual Machine.
from eth.vm.forks import (
IstanbulVM,
)
from eth.vm import (
opcode_values
)
from tests.core.opcodes.test_opcodes import (
assemble,
CANONICAL_ADDRESS_B,
[{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"internalType": "string",
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
@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
@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 / 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 / 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 / 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: