Skip to content

Instantly share code, notes, and snippets.

View matejker's full-sized avatar
🙃

Matej Kerekrety matejker

🙃
View GitHub Profile
def get_score(board: Ternary, depth: int, player: int = 2) -> Tuple[int, bool]:
winner = whois_winner(board)
if winner == player:
return 10 - depth, True
elif winner < 1:
return 0, winner == 0
else:
return depth - 10, True
from tic_tac_toe.utils.permutations import get_all_boards
symmetry_classes, all_boards = get_all_boards(exclude_winners=False)
counts = [len(sc) for sc in symmetry_classes]
counts_all = [len(b) for b in all_boards]
print(f"Unique boards: {counts}, sum: {sum(counts)}")
print(f"All boards: {counts_all}, sum: {sum(counts_all)}")
symmetry_classes_menace, all_boards_menace = get_all_boards(exclude_winners=True)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matejker
matejker / BinaryFiniteField.py
Last active May 13, 2021 21:15
Basic arithmetic operations on finite fields or Galois field of order 2^n
IRR_POLYNOMIALS = [2, 7, 11, 19]
class BinaryFiniteField:
""" Basic arithmetic operations on finite fields or Galois field of order 2^n
Params:
- a (int) element of the 2^n set
- n (int) exponent
- r (int): irreducible polynomial over GF(2^n)
def affine_lines(n: int) -> list:
return (
[[[x + ((t * x + u) % n) * n for x in range(n)] for u in range(n)] for t in range(0, n)] +
[[[x + y * n for y in range(n)] for x in range(n)]]
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matejker
matejker / Cupon collector's problem.ipynb
Last active September 11, 2020 08:52
Cupon collector's problem / The Double Dixie Cup Problem
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.