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 / 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 / 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 / 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 / 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:20
The simplest possible way of printing the first 100 fibonacci numbers in python
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):
@Sasszem
Sasszem / Menu.hpp
Created April 16, 2020 08:38
Simple rotary-encoder driven LCD menu for Arduino
// WARNING: Only include this file ONCE in your project
// Made by Sasszem, 2020
// If you ever make any money using this you own me a beer
#include <LiquidCrystal.h>
#include <Arduino.h>
namespace Menu
{
struct Entry {
@Sasszem
Sasszem / polc.py
Created April 17, 2020 09:11
Brute-forcing a simple combinatorical problem to verify the correctness of out solution
def num_to_str(n):
return "{:012b}".format(n)
def has_four(s):
return sum(int(ch) for ch in s)==4
def no_next_to(s):
return s.find("11")==-1
all_possible = list(filter(no_next_to, filter(has_four, map(num_to_str, range(2**12)))))
@Sasszem
Sasszem / jsonIter.py
Created May 29, 2020 18:14
Extract JSON from text - a quick-and-dirty iterator. Handles braces in strings and escapes (possibly).
def extractJSON(string):
extracted = ""
seen = 0
in_string = False
escape = False
for char in string:
if char=="{" and not in_string:
seen += 1
@Sasszem
Sasszem / paulunger.py
Created November 27, 2020 17:59
Simple Paul-Unger state table optimalization helper for single input sequential networks
from collections import deque
"""
Input your (not) fully specified state table here
"""
T = [
["a", ["h", "1"], ["f", "-"]],
["b", ["c", "1"], ["h", "1"]],
["c", ["b", "0"], ["a", "0"]],
["d", ["d", "1"], ["-", "0"]],
@Sasszem
Sasszem / message.c
Created December 8, 2020 16:42
Last programming assignment in the semester: write a program that prints what we liked to STDOUT and what we did not to STDERR. (in Hungarian)
#include <stdint.h>
#include <stdio.h>
uint64_t csoeoe(uint64_t thatFirstParam, uint64_t paramNumberOne, uint64_t dQw4w9WgXcQ) {
return (int64_t)(((__int128_t)thatFirstParam*paramNumberOne)%dQw4w9WgXcQ);
}
uint64_t fueuetoeoecsoeoe(uint64_t ZWxzb1BhcmFtZXRlcg, uint64_t bWFzb2Rpa1BhcmFtZXRlcg, uint64_t dXRvbHNvUGFyYW1ldGVy)
{
uint64_t dmFsYW1pUmFuZG9tVmFsdG96bw = 1;