Skip to content

Instantly share code, notes, and snippets.

View kldtz's full-sized avatar

Tobias Kolditz kldtz

View GitHub Profile
from collections import deque
SIZE = 8
def knight_distance(i: int, j: int) -> list[list[int]]:
board = [[None] * SIZE for _ in range(SIZE)]
q = deque([(i, j, 0)])
while q:
(i, j, d) = q.popleft()
if not 0 <= i < SIZE or not 0 <= j < SIZE or board[i][j] is not None:
@kldtz
kldtz / suffix_tree.py
Last active March 17, 2021 07:12
Educational implementation of Ukkonen's algorithm
from os import mkdir
import sys
class AuxState:
def __init__(self, root):
self.id = '⊥'
self.root = root
self.suffix_link = None
self.transitions = {'*': self.root}
@kldtz
kldtz / matchstick_equations.py
Created July 28, 2019 15:49
Matchstick equation solver
from itertools import product
SYMBOLS = {
'0': (1, 1, 1, 1, 1, 1, 0, 0, 0, 0),
'1': (0, 0, 0, 1, 1, 0, 0, 0, 0, 0),
'2': (1, 0, 1, 1, 0, 1, 1, 0, 0, 0),
'3': (0, 0, 1, 1, 1, 1, 1, 0, 0, 0),
'4': (0, 1, 0, 1, 1, 0, 1, 0, 0, 0),
'5': (0, 1, 1, 0, 1, 1, 1, 0, 0, 0),
'6': (1, 1, 1, 0, 1, 1, 1, 0, 0, 0),