Skip to content

Instantly share code, notes, and snippets.

View dotapetro's full-sized avatar

dotapetro

View GitHub Profile
import time
import random
import sys
sys.setrecursionlimit(3000)
def timing(f):
def wrap(*args):
time1 = time.time()
ret = f(*args)
@dotapetro
dotapetro / HuffmanCode.py
Last active June 27, 2017 15:15
Just another one realization of Huffman Code
from math import floor
what_to_zip = '''
Scene: A cafe. One table is occupied by a group of Vikings with horned helmets on. A man and his wife enter.
Man (Eric Idle): You sit here, dear.
Wife (Graham Chapman in drag): All right.
Man (to Waitress): Morning!
Waitress (Terry Jones, in drag as a bit of a rat-bag): Morning!
Man: Well, what've you got?
Waitress: Well, there's egg and bacon; egg sausage and bacon; egg and spam; egg bacon and spam; egg bacon sausage and spam; spam bacon sausage and spam; spam egg spam spam bacon and spam; spam sausage spam spam bacon spam tomato and spam;
size, node = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(size)]
def get_nodes_list(graph):
return [[neighbour for neighbour in range(len(row)) if row[neighbour]] for row in graph]
def make_dict(graph):
nodes = get_nodes_list(graph)
class Node:
def __init__(self, name):
self.name = name
self.neighbours = []
def add_neighbour_to_self(self, neighbour):
self.neighbours.append(neighbour)
def find_neighbour_index(self, name):
for i in range(len(self.neighbours)):
@dotapetro
dotapetro / hashtable.py
Created April 11, 2017 16:17
Simplified python dict
class Hashtable:
def __init__(self, size=29):
self.keys = [[]] * size
self.values = [[]] * size
self.real_keys = []
self.size = size
def get_hash(self, something):
something = str(something)
@dotapetro
dotapetro / queue.py
Created April 2, 2017 12:41
Queue oop python 3.x lib
import sys
class Queue:
def __init__(self, size=0):
self.queueObject = []
self.symbols = []
self.count = {}
self.opposites = {}
self.boofer = []
@dotapetro
dotapetro / queue.py
Last active April 2, 2017 14:20
Homevork 3 ex (Queue OOP python lib)
import sys
class Queue:
def __init__(self, size=0):
self.queueObject = []
self.symbols = []
self.count = {}
self.opposites = {}
self.boofer = []