Skip to content

Instantly share code, notes, and snippets.

View YariKartoshe4ka's full-sized avatar
🤯
Too many things to do and too little time

YariKartoshe4ka

🤯
Too many things to do and too little time
View GitHub Profile
# Alternative implementation of pygame.Rect that uses floats rather than integers
#
# Use FRect from pygame-ce instead of this!
# https://pyga.me/docs/ref/rect.html
#
# Don't question the implementation strategy, this is perfect
# Repurposed from another project of mine
# Constants needed for my direct translation of SDL_IntersectRectAndLine
@m00nlight
m00nlight / gist:daa6786cc503fde12a77
Last active April 26, 2025 15:50
Python KMP algorithm
class KMP:
def partial(self, pattern):
""" Calculate partial match table: String -> [Int]"""
ret = [0]
for i in range(1, len(pattern)):
j = ret[i - 1]
while j > 0 and pattern[j] != pattern[i]:
j = ret[j - 1]
ret.append(j + 1 if pattern[j] == pattern[i] else j)