Skip to content

Instantly share code, notes, and snippets.

@dalemyers
dalemyers / knights_tour.py
Last active January 12, 2020 12:15
Implementation of the knights tour algorithm in Python
from typing import List, Optional, Tuple
Square = Tuple[int, int]
SIZE = 8
assert SIZE <= 20, "Too large a size will overflow the stack"
def next_possible_squares(x: int, y: int, squares: List[Square]) -> List[Square]:
"""Determine the next possible valid squares based on the current square and the previously visited squares.
def get_entry_size(entry: Any) -> int:
"""Get the approximate size an entry will be in JSON.
Notes: Doesn't check for escaped characters in strings, so the size returned
will essentially always be a lower bound.
:param entry: The entry to get the size of
:returns: A size in bytes
"""