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
from collections import namedtuple, deque | |
from sys import stdin, stdout | |
class SVM: | |
def __init__(self, progmem = "H", stack = [], status = [0, False]): | |
self.progmem = progmem | |
self.stack = deque(stack) | |
self.PC, self.HALT = status | |
def step(self): |
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
import random | |
import timeit | |
def setup_map(data, num): | |
for _ in range(num): | |
data[random.random()] = random.random() | |
map = {} | |
setup_map(map, 100000) |
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
import timeit | |
def fib(n): | |
if n==1 or n==2: | |
return 1 | |
return fib(n-1) + fib(n-2) | |
print(timeit.timeit("fib(10)", "from __main__ import fib", number=1, )) | |
print(timeit.timeit("fib(20)", "from __main__ import fib", number=1, )) | |
print(timeit.timeit("fib(30)", "from __main__ import fib", number=1, )) | |
print(timeit.timeit("fib(40)", "from __main__ import fib", number=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 swap(char): | |
return chr(swap_ascii(ord(char))) | |
def swap_ascii(code): | |
if code>=65 and code<=90: | |
return 155-code | |
# 90 - (code-65) = 90+65-code = 115-code | |
elif code>=97 and code<=122: | |
return 219-code | |
# similarly from 112-(code-97) |
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
import random | |
# gyors kombinatorikai modell a 10 élre | |
all_edges = [(i, j) for i in range(5) for j in range(5) if i!=j and i<j] | |
def negyszog_e(elek): | |
# akkor négyszög ha a négy él négy csúcsot ad meg és minden csúcs fokszáma 2 | |
pontok = {} | |
for i,j in elek: | |
pontok[i] = pontok.get(i, 0) + 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
####### | |
# Map # | |
####### | |
######### | |
#Key A # | |
# 2# | |
############# ### |
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
# a *very simple* text adventure game in python | |
# to practice control flow statements | |
# only contains IF-ELSE, WHILE statements, STRING, INTEGER and BOOL variables | |
# INPUT and PRINT | |
####### | |
# Map # | |
####### | |
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
local NUM_TO_CALC = 10 | |
print("Fib1 - uses 'brute-force recursive method':") | |
print("-------------------------------------------") | |
local called = {} | |
-- hashmap to store call statistics | |
local function fib(n, depth) | |
depth = depth or 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
from sys import stdin, stdout | |
def readTree(numNodes): | |
"""Does what it says on the box. | |
The tree is stored like tree[n] = [...], the list of the child nodes of node n""" | |
nodes = {} | |
for i in range(1,numNodes+1): | |
# Why would I write readable code? | |
nodes[i] = list(map(int,stdin.readline().strip().split()[:-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
import json | |
import struct | |
import array | |
def _toBytes(list): | |
return array.array('B', list).tostring() | |
def _toId(int): | |
return _toBytes((int %256, int//256)) |