Skip to content

Instantly share code, notes, and snippets.

View Sasszem's full-sized avatar
💥
Burning the dynamite at both ends

László Baráth Sasszem

💥
Burning the dynamite at both ends
  • Szolnok, Hungary
View GitHub Profile
@Sasszem
Sasszem / hashmap.py
Created April 14, 2020 19:15
Quadratic vs linear time complexity showcase
import random
import timeit
def setup_map(data, num):
for _ in range(num):
data[random.random()] = random.random()
map = {}
setup_map(map, 100000)
@Sasszem
Sasszem / fibo.py
Created April 14, 2020 19:13
Showing exponential time complexity of the simple recursive method
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, ))
@Sasszem
Sasszem / atbash.py
Created April 14, 2020 19:09
Smart atbash coding in Python
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)
@Sasszem
Sasszem / monte_negyszog.py
Last active April 6, 2020 17:37
Python monte-carlo
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
@Sasszem
Sasszem / game_lists.py
Created February 23, 2020 22:11
Text adventore game rewritten with lists
#######
# Map #
#######
#########
#Key A #
# 2#
############# ###
@Sasszem
Sasszem / adventure_1.py
Last active February 13, 2020 23:41
A simple text adventure game in python
# 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 #
#######
@Sasszem
Sasszem / fibo.lua
Created October 13, 2018 20:59
Demonstration of the power of simple dynamic programming using the fibonacci sequance
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
@Sasszem
Sasszem / faszelso.py
Created October 1, 2018 00:57
OKTV 2017/18 turn 2 ex. 3
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]))
@Sasszem
Sasszem / pynp.py
Created July 17, 2018 23:51
A socket wrapper to help write custom protocols
import json
import struct
import array
def _toBytes(list):
return array.array('B', list).tostring()
def _toId(int):
return _toBytes((int %256, int//256))
@Sasszem
Sasszem / prim.py
Created July 17, 2018 23:10
A PyOpenGL based 3d opbject renderer class with transformations
# -*- coding: utf-8 -*-
from OpenGL.GL import *
from array import array
glEnableClientState(GL_VERTEX_ARRAY)
class Primitive():
def __init__(self,vert,colors,colors2,drawMode,ind,x=0,y=0,z=0,s=0,rX=0,rY=0,rZ=0,sX=1,sY=1,sZ=1):
#Csúcstömbadatok tárolása/Storing vertex-data
self.vert=array('f',list(vert))
self.vert=glGenBuffers(1)