Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍🎓
Digging the EVM

Voith Mascarenhas voith

👨‍🎓
Digging the EVM
View GitHub Profile
@voith
voith / withdraw.sol
Last active Mar 16, 2021
Sample solidity function
View withdraw.sol
pragma solidity ^0.5.16;
contract DummyERC20 is ERC20 {
function withdraw() external {
uint256 amount = balances[msg.sender];
require(msg.sender.call.value(amount)());
balances[msg.sender] = 0;
}
}
View advent_of_code_2_2.py
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 Oct 19, 2020
Example to add two numbers using the Ethereum virtual Machine.
View evm_add.py
from eth.vm.forks import (
IstanbulVM,
)
from eth.vm import (
opcode_values
)
from tests.core.opcodes.test_opcodes import (
assemble,
CANONICAL_ADDRESS_B,
View Comptroller_ABIi.json
[{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"internalType": "string",
View substrings.py
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 Dec 13, 2019
total number of connected regions in a grid
View grid_dfs.py
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 Nov 30, 2019
Findall possible ways €2 can be split using coins 1p, 2p, 5p, 10p, 20p, 50p, €1 (100p) and €2 (200p)
View coin_change.py
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 Nov 28, 2019
sum of the numbers on the diagonals in a 1001 by 1001 spiral
View sum_spiral_diagonals.py
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 Nov 16, 2019
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.
View quadratic_primes.py
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 Nov 12, 2019
value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction par
View reciprocal_cycles.py
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: