diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8a7aa7..244d398 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,9 @@ jobs: - python: "3.10" toxenv: py310 os: ubuntu-latest + - python: "3.11" + toxenv: py311 + os: ubuntu-latest - python: pypy-3.7 toxenv: pypy37 os: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7b36b..33a8949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased ### Changed - - Updated dependency on automata-lib to version 6.0.2 + - Updated dependency on automata-lib to version 7.0.1 + +### Added + - Now testing on Python 3.11 ## 2.2.0 - 2021-10-21 ### Added diff --git a/permuta/permutils/pin_words.py b/permuta/permutils/pin_words.py index cb2192b..8db99b9 100644 --- a/permuta/permutils/pin_words.py +++ b/permuta/permutils/pin_words.py @@ -263,13 +263,12 @@ def pinword_contains(cls, word: str, u_word: str): @classmethod def make_nfa_for_pinword(cls, u_word: str) -> "NFA": """NFA for pinword""" - prefix = "" def new_state(states) -> None: - states.add(prefix + str(len(states))) + states.add(len(states)) - def last_state(states) -> str: - return prefix + str(len(states) - 1) + def last_state(states) -> int: + return len(states) - 1 def add_a_star(states, transitions) -> None: new_state(states) @@ -308,19 +307,19 @@ def add_sp(u_i, states, transitions) -> None: position = nxt decomp = [cls.sp_to_m(x) for x in cls.factor_pinword(u_word)] - input_symbols = set(DIRS) - initial_state = "0" - states: Set[str] = set() - transitions: DefaultDict[str, dict] = defaultdict(dict) + input_symbols = frozenset(DIRS) + initial_state = 0 + states: Set[int] = set() + transitions: DefaultDict[int, dict] = defaultdict(dict) add_a_star(states, transitions) for u_i in decomp: add_sp(u_i, states, transitions) - final_states = {last_state(states)} + final_states = frozenset({last_state(states)}) return NFA( - states=states, + states=frozenset(states), input_symbols=input_symbols, transitions=transitions, initial_state=initial_state, @@ -328,88 +327,57 @@ def add_sp(u_i, states, transitions) -> None: ) @staticmethod - def dfa_name_reset(dfa_in: "DFA", minimize=True) -> "DFA": - """DFA name reset.""" - if minimize: - return dfa_in.minify() - m_dict: Dict[str, str] = {} - for state in dfa_in.states: - m_dict[state] = str(len(m_dict)) - - return DFA( - states={m_dict[x] for x in dfa_in.states}, - input_symbols=dfa_in.input_symbols, - transitions={ - m_dict[x]: {k: m_dict[v] for k, v in dfa_in.transitions[x].items()} - for x in dfa_in.transitions - }, - initial_state=m_dict[dfa_in.initial_state], - final_states={m_dict[x] for x in dfa_in.final_states}, - ) - - @staticmethod + @lru_cache(maxsize=None) def make_dfa_for_m() -> "DFA": """Returns DFA for M.""" return DFA( - states={"0", "1", "2", "3"}, - input_symbols=set(DIRS), + states=frozenset({0, 1, 2, 3}), + input_symbols=frozenset(DIRS), transitions={ - "0": {"U": "1", "D": "1", "L": "2", "R": "2"}, - "1": {"U": "3", "D": "3", "L": "2", "R": "2"}, - "2": {"U": "1", "D": "1", "L": "3", "R": "3"}, - "3": {"U": "3", "D": "3", "L": "3", "R": "3"}, + 0: {"U": 1, "D": 1, "L": 2, "R": 2}, + 1: {"U": 3, "D": 3, "L": 2, "R": 2}, + 2: {"U": 1, "D": 1, "L": 3, "R": 3}, + 3: {"U": 3, "D": 3, "L": 3, "R": 3}, }, - initial_state="0", - final_states={"0", "1", "2"}, + initial_state=0, + final_states=frozenset({0, 1, 2}), ) @classmethod def make_dfa_for_pinword(cls, word: str) -> "DFA": """Returns DFA for pinword.""" - return cls.dfa_name_reset(DFA.from_nfa(cls.make_nfa_for_pinword(word))) + return DFA.from_nfa(cls.make_nfa_for_pinword(word)) @classmethod def make_dfa_for_perm(cls, perm: "Perm") -> "DFA": """Returns DFA for Perm.""" pinwords = cls.pinwords_for_basis((perm,)) - out_dfa: "DFA" = None + out_dfa: "DFA" = DFA.empty_language(frozenset(DIRS)) sorted_pinwords = sorted(pinwords) for word in sorted_pinwords: - if out_dfa is None: - out_dfa = cls.make_dfa_for_pinword(word) - else: - out_dfa2 = cls.make_dfa_for_pinword(word) - for_union = out_dfa.union(out_dfa2) - out_dfa = cls.dfa_name_reset(for_union) + out_dfa2 = cls.make_dfa_for_pinword(word) + out_dfa = out_dfa.union(out_dfa2) return out_dfa @classmethod def make_dfa_for_basis_from_pinwords(cls, basis: List["Perm"]) -> "DFA": """Returns DFA for basis from list of pinwords""" pinwords = cls.pinwords_for_basis(basis) - out_dfa: "DFA" = None + out_dfa: "DFA" = DFA.empty_language(frozenset(DIRS)) sorted_pinwords = sorted(pinwords) for word in sorted_pinwords: - if out_dfa is None: - out_dfa = cls.make_dfa_for_pinword(word) - else: - out_dfa2 = cls.make_dfa_for_pinword(word) - out_dfa = out_dfa.union(out_dfa2) - # out_dfa = cls.dfa_name_reset(for_union) + out_dfa2 = cls.make_dfa_for_pinword(word) + out_dfa = out_dfa.union(out_dfa2) return out_dfa @classmethod def make_dfa_for_basis_from_db(cls, basis: List["Perm"]) -> "DFA": """Returns DFA for basis from db.""" - out_dfa: "DFA" = None + out_dfa: "DFA" = DFA.empty_language(frozenset(DIRS)) sorted_basis = sorted(basis) - for word in sorted_basis: - if out_dfa is None: - out_dfa = cls.load_dfa_for_perm(word) - else: - out_dfa2 = cls.load_dfa_for_perm(word) - for_union = out_dfa.union(out_dfa2) - out_dfa = cls.dfa_name_reset(for_union) + for perm in sorted_basis: + out_dfa2 = cls.load_dfa_for_perm(perm) + out_dfa = out_dfa.union(out_dfa2) return out_dfa @classmethod @@ -495,8 +463,7 @@ def has_finite_pinperms(cls, basis, use_db=False, dfa: "DFA" = None) -> bool: """Check if basis has finite pinperms""" if dfa is None: dfa = cls.make_dfa_for_basis(basis, use_db) - dfa = dfa.complement() - dfa = cls.dfa_name_reset(cls.make_dfa_for_m() & dfa) + dfa = cls.make_dfa_for_m().difference(dfa) return dfa.isfinite() is True @classmethod @@ -521,15 +488,10 @@ def store_dfa_for_perm(cls, perm, in_dfa=None) -> None: if in_dfa is None: in_dfa = cls.make_dfa_for_perm(perm) with open(str(path), "w") as file_object: - file_object.write( - f"DFA(states={in_dfa.states}, " - + f"input_symbols={in_dfa.input_symbols}, " - + f"transitions={dict(in_dfa.transitions)}, " - + f"initial_state='{in_dfa.initial_state}', " - + f"final_states={in_dfa.final_states})\n" - ) + file_object.write(repr(in_dfa)) @classmethod + @lru_cache(maxsize=None) def load_dfa_for_perm(cls, perm) -> "DFA": """Loads the DFA for the specified Perm from file.""" directory = f"dfa_db/S{len(perm)}/" diff --git a/setup.py b/setup.py index 1cb14fb..66337ef 100755 --- a/setup.py +++ b/setup.py @@ -51,6 +51,6 @@ def get_version(rel_path): "Topic :: Education", "Topic :: Scientific/Engineering :: Mathematics", ], - install_requires=["automata-lib==6.0.2"], + install_requires=["automata-lib==7.0.1"], entry_points={"console_scripts": ["permtools=permuta.cli:main"]}, ) diff --git a/tests/permutils/test_pinwords.py b/tests/permutils/test_pinwords.py index 4145770..3e6ec04 100644 --- a/tests/permutils/test_pinwords.py +++ b/tests/permutils/test_pinwords.py @@ -3277,859 +3277,6 @@ def test_make_dfa_for_pinword(): ) -def test_dfa_name_reset(): - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("1UR2")) == DFA( - states={ - "{0,1}", - "{0,4,5}", - "{{0,2,4},{0,4}}", - "{0,2}", - "{0,1,3}", - "{{0,1,3,4,6},{0,1,4,6}}", - "{0}", - "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0,1}", "R": "{0}"}, - "{0,1}": {"L": "{0}", "D": "{0}", "U": "{0,1}", "R": "{0,2}"}, - "{0,2}": {"L": "{0}", "D": "{0}", "U": "{0,1,3}", "R": "{0}"}, - "{0,1,3}": {"L": "{0}", "D": "{0}", "U": "{0,1}", "R": "{{0,2,4},{0,4}}"}, - "{0,4,5}": { - "L": "{0,4,5}", - "D": "{{0,2,4},{0,4}}", - "U": "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - "R": "{{0,2,4},{0,4}}", - }, - "{{0,1,3,4,6},{0,1,4,6}}": { - "L": "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - "D": "{{0,2,4},{0,4}}", - "U": "{{0,1,3,4,6},{0,1,4,6}}", - "R": "{{0,2,4},{0,4}}", - }, - "{{0,2,4},{0,4}}": { - "L": "{0,4,5}", - "D": "{{0,2,4},{0,4}}", - "U": "{{0,1,3,4,6},{0,1,4,6}}", - "R": "{{0,2,4},{0,4}}", - }, - "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}": { - "L": "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - "D": "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - "U": "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - "R": "{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3,4,6,7},{0,1,4,6,7},{0,2,4,7},{0,4,5,7},{0,4,7}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("3D23")) == DFA( - states={ - "{0,1}", - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9},{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}", - "{{0,1,3},{0,3}}", - "{{0,2,3,4},{0,3,4}}", - "{0,1,3,6,8}", - "{0,2}", - "{0,3,4,6,7}", - "{0}", - "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - "{0,3,5}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0,1}", "U": "{0}", "R": "{0}"}, - "{0,1}": {"L": "{0,2}", "D": "{0,1}", "U": "{0}", "R": "{0}"}, - "{0,2}": {"L": "{0}", "D": "{{0,1,3},{0,3}}", "U": "{0}", "R": "{0}"}, - "{0,3,5}": { - "L": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3},{0,3}}", - "U": "{0,3,5}", - "R": "{{0,1,3},{0,3}}", - }, - "{0,3,4,6,7}": { - "L": "{0,3,4,6,7}", - "D": ( - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9}," - "{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - ), - "U": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - }, - "{0,1,3,6,8}": { - "L": ( - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9}," - "{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - ), - "D": "{0,1,3,6,8}", - "U": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - }, - "{{0,2,3,4},{0,3,4}}": { - "L": "{{0,2,3,4},{0,3,4}}", - "D": "{{0,1,3},{0,3}}", - "U": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,1,3},{0,3}}", - }, - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9},{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}": { - "L": ( - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9}," - "{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - ), - "D": ( - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9}," - "{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - ), - "U": ( - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9}," - "{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - ), - "R": ( - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9}," - "{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - ), - }, - "{{0,3,4,6},{0,3,5,6},{0,3,6}}": { - "L": "{0,3,4,6,7}", - "D": "{0,1,3,6,8}", - "U": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,3,4,6},{0,3,5,6},{0,3,6}}", - }, - "{{0,1,3},{0,3}}": { - "L": "{{0,2,3,4},{0,3,4}}", - "D": "{{0,1,3},{0,3}}", - "U": "{0,3,5}", - "R": "{{0,1,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={ - "{{0,1,3,6,8,9},{0,2,3,4,6,7,9},{0,3,4,6,7,9},{0,3,5,6,9},{0,3,6,9}}" - }, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("141R4")) == DFA( - states={ - "{0,1}", - "{0,2,3,6,8}", - "{0}", - "{0,1,3,4,6,7}", - "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "{{0,1,3},{0,2,3},{0,3}}", - "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "{0,1,3,4}", - "{0,2}", - ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "{0,1,10,3,4,6,7,9}", - "{0,3,5}", - "{0,11,3,5,6,9}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0,2}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0}", - "U": "{0,2}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{0,1}": { - "L": "{0}", - "D": "{0}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{0,1}", - }, - "{0,3,5}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{0,3,5}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - }, - "{0,1,3,4}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{0,1,3,4}", - }, - "{0,1,3,4,6,7}": { - "L": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "U": "{0,2,3,6,8}", - "R": "{0,1,3,4,6,7}", - }, - "{0,2,3,6,8}": { - "L": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "U": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - }, - "{0,11,3,5,6,9}": { - "L": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "D": "{0,11,3,5,6,9}", - "U": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "R": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - }, - "{0,1,10,3,4,6,7,9}": { - "L": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "D": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "U": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "R": "{0,1,10,3,4,6,7,9}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{0,3,5}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{0,1,3,4}", - }, - "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}": { - "L": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "U": "{{0,1,3,4,6},{0,2,3,6},{0,3,5,6},{0,3,6}}", - "R": "{0,1,3,4,6,7}", - }, - ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ): { - "L": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "D": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "U": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "R": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9}," - "{0,12,2,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - }, - "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}": { - "L": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "D": "{0,11,3,5,6,9}", - "U": "{{0,1,3,4,6,7,9},{0,2,3,6,8,9},{0,2,3,6,9},{0,3,6,9}}", - "R": "{0,1,10,3,4,6,7,9}", - }, - }, - initial_state="{0}", - final_states={ - ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,9},{0,12,2,3,6,8,9}," - "{0,12,2,3,6,9},{0,12,3,6,9}}" - ) - }, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("1R")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,1}": {"L": "{0}", "D": "{0}", "U": "{0,2}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("2L")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0,1}", "D": "{0}", "U": "{0}", "R": "{0}"}, - "{0,1}": {"L": "{0,1}", "D": "{0}", "U": "{0,2}", "R": "{0}"}, - "{0,2}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{0}", - "U": "{0}", - "R": "{0}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("4L2")) == DFA( - states={ - "{0,1}", - "{0,2}", - "{0,3,4}", - "{0,3,5}", - "{{0,1,3},{0,2,3},{0,3}}", - "{0}", - "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,1}": {"L": "{0}", "D": "{0,2}", "U": "{0}", "R": "{0,1}"}, - "{0,2}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{0}", - "U": "{0}", - "R": "{0,1}", - }, - "{0,3,4}": { - "L": "{0,3,4}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{0,3,5}": { - "L": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{0,3,5}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{0,3,4}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{0,3,5}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}": { - "L": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - "U": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - "R": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6},{0,3,6}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("3R")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0,1}", "D": "{0}", "U": "{0}", "R": "{0}"}, - "{0,1}": {"L": "{0,1}", "D": "{0,2}", "U": "{0}", "R": "{0}"}, - "{0,2}": { - "L": "{0,1}", - "D": "{0}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("41R11")) == DFA( - states={ - "{{0,3,5,6,8},{0,3,6,8}}", - "{0,1}", - "{0}", - "{0,1,3,4,6,7}", - "{{0,1,3},{0,2,3},{0,3}}", - "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "{0,1,3,4}", - "{0,2}", - "{{0,11,3,5,6,8,9},{0,11,3,6,8,9}}", - ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9},{0,11,12,3,6,8,9}," - "{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "{0,1,10,3,4,6,7,9}", - "{0,3,5}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0,2}", "U": "{0}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0,2}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{0,1}": { - "L": "{0}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{0}", - "R": "{0,1}", - }, - "{0,1,3,4}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{0,3,5}", - "R": "{0,1,3,4}", - }, - "{0,3,5}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - }, - "{0,1,3,4,6,7}": { - "L": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "U": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "R": "{0,1,3,4,6,7}", - }, - "{0,1,10,3,4,6,7,9}": { - "L": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "D": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "U": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9}," - "{0,11,12,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "R": "{0,1,10,3,4,6,7,9}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{0,1,3,4}", - }, - "{{0,3,5,6,8},{0,3,6,8}}": { - "L": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "U": "{{0,3,5,6,8},{0,3,6,8}}", - "R": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - }, - "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}": { - "L": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,6},{0,3,6}}", - "U": "{{0,3,5,6,8},{0,3,6,8}}", - "R": "{0,1,3,4,6,7}", - }, - ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9},{0,11,12,3,6,8,9}," - "{0,12,2,3,6,9},{0,12,3,6,9}}" - ): { - "L": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9}," - "{0,11,12,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "D": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9}," - "{0,11,12,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "U": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9}," - "{0,11,12,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - "R": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9}," - "{0,11,12,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - }, - "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}": { - "L": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "D": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "U": "{{0,11,3,5,6,8,9},{0,11,3,6,8,9}}", - "R": "{0,1,10,3,4,6,7,9}", - }, - "{{0,11,3,5,6,8,9},{0,11,3,6,8,9}}": { - "L": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "D": "{{0,1,3,4,6,7,9},{0,2,3,6,9},{0,3,5,6,8,9},{0,3,6,9}}", - "U": "{{0,11,3,5,6,8,9},{0,11,3,6,8,9}}", - "R": ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9}," - "{0,11,12,3,6,8,9},{0,12,2,3,6,9},{0,12,3,6,9}}" - ), - }, - }, - initial_state="{0}", - final_states={ - ( - "{{0,1,10,12,3,4,6,7,9},{0,11,12,3,5,6,8,9},{0,11,12,3,6,8,9}," - "{0,12,2,3,6,9},{0,12,3,6,9}}" - ) - }, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("4L41D4")) == DFA( - states={ - "{0,3,6,7}", - "{0,1}", - "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "{0,1,3,4,6,8}", - "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "{0,3}", - "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}", - "{0,1,3,4}", - "{0,2}", - "{0}", - "{0,3,5}", - "{0,11,3,5,6,9}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,1}": {"L": "{0}", "D": "{0,2}", "U": "{0}", "R": "{0,1}"}, - "{0,2}": {"L": "{0,3}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,3}": {"L": "{0,3}", "D": "{0,3,5}", "U": "{0,3}", "R": "{0,1,3,4}"}, - "{0,3,5}": { - "L": "{0,3}", - "D": "{0,3,5}", - "U": "{0,3}", - "R": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - }, - "{0,1,3,4}": { - "L": "{0,3}", - "D": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "U": "{0,3}", - "R": "{0,1,3,4}", - }, - "{0,3,6,7}": { - "L": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "U": "{0,3,6,7}", - "R": "{0,1,3,4,6,8}", - }, - "{0,1,3,4,6,8}": { - "L": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "U": "{0,3,6,7}", - "R": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - }, - "{0,11,3,5,6,9}": { - "L": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "D": "{0,11,3,5,6,9}", - "U": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "R": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - }, - "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}": { - "L": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "D": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "U": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "R": "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}", - }, - ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ): { - "L": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "D": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "U": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "R": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - }, - "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}": { - "L": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "U": "{0,3,6,7}", - "R": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - }, - "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}": { - "L": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "D": "{0,11,3,5,6,9}", - "U": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "R": "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}", - }, - }, - initial_state="{0}", - final_states={ - ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ) - }, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("4")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0,2}", "U": "{0}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0,2}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{0,1}": { - "L": "{0}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{0}", - "R": "{0,1}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("1R")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,1}": {"L": "{0}", "D": "{0}", "U": "{0,2}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("4L41D4")) == DFA( - states={ - "{0,3,6,7}", - "{0,1}", - "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "{0,1,3,4,6,8}", - "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "{0,3}", - "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}", - "{0,1,3,4}", - "{0,2}", - "{0}", - "{0,3,5}", - "{0,11,3,5,6,9}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,1}": {"L": "{0}", "D": "{0,2}", "U": "{0}", "R": "{0,1}"}, - "{0,2}": {"L": "{0,3}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,3}": {"L": "{0,3}", "D": "{0,3,5}", "U": "{0,3}", "R": "{0,1,3,4}"}, - "{0,3,5}": { - "L": "{0,3}", - "D": "{0,3,5}", - "U": "{0,3}", - "R": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - }, - "{0,1,3,4}": { - "L": "{0,3}", - "D": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "U": "{0,3}", - "R": "{0,1,3,4}", - }, - "{0,3,6,7}": { - "L": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "U": "{0,3,6,7}", - "R": "{0,1,3,4,6,8}", - }, - "{0,1,3,4,6,8}": { - "L": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "U": "{0,3,6,7}", - "R": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - }, - "{0,11,3,5,6,9}": { - "L": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "D": "{0,11,3,5,6,9}", - "U": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "R": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - }, - "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}": { - "L": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "D": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "U": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "R": "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}", - }, - ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ): { - "L": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "D": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "U": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - "R": ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ), - }, - "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}": { - "L": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "D": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - "U": "{0,3,6,7}", - "R": "{{0,1,3,4,6},{0,2,3,5,6},{0,3,5,6},{0,3,6}}", - }, - "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}": { - "L": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "D": "{0,11,3,5,6,9}", - "U": "{{0,2,3,5,6,9},{0,3,6,7,9},{0,3,6,9}}", - "R": "{{0,1,10,3,4,6,8,9},{0,1,10,3,4,6,9}}", - }, - }, - initial_state="{0}", - final_states={ - ( - "{{0,1,10,12,3,4,6,8,9},{0,1,10,12,3,4,6,9},{0,11,12,2,3,5,6,9}," - "{0,11,12,3,5,6,9},{0,12,3,6,7,9},{0,12,3,6,9}}" - ) - }, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("4")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0,2}", "U": "{0}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0,2}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{0,1}": { - "L": "{0}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{0}", - "R": "{0,1}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("31")) == DFA( - states={ - "{0,1}", - "{0,2}", - "{0,3,4}", - "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - "{{0,1,3},{0,2,3}}", - "{0}", - "{0,3,5}", - }, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0,1}", "D": "{0,2}", "U": "{0}", "R": "{0}"}, - "{0,1}": {"L": "{0,1}", "D": "{{0,1,3},{0,2,3}}", "U": "{0}", "R": "{0}"}, - "{0,2}": {"L": "{{0,1,3},{0,2,3}}", "D": "{0,2}", "U": "{0}", "R": "{0}"}, - "{0,3,5}": { - "L": "{{0,1,3},{0,2,3}}", - "D": "{{0,1,3},{0,2,3}}", - "U": "{0,3,5}", - "R": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - }, - "{0,3,4}": { - "L": "{{0,1,3},{0,2,3}}", - "D": "{{0,1,3},{0,2,3}}", - "U": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - "R": "{0,3,4}", - }, - "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}": { - "L": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - "D": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - "U": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - "R": "{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}", - }, - "{{0,1,3},{0,2,3}}": { - "L": "{{0,1,3},{0,2,3}}", - "D": "{{0,1,3},{0,2,3}}", - "U": "{0,3,5}", - "R": "{0,3,4}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3,6},{0,2,3,6},{0,3,4,6},{0,3,5,6}}"}, - ) - assert PinWords.dfa_name_reset(PinWords.make_dfa_for_pinword("1R")) == DFA( - states={"{{0,1,3},{0,2,3},{0,3}}", "{0,1}", "{0}", "{0,2}"}, - input_symbols={"L", "D", "U", "R"}, - transitions={ - "{0}": {"L": "{0}", "D": "{0}", "U": "{0}", "R": "{0,1}"}, - "{0,1}": {"L": "{0}", "D": "{0}", "U": "{0,2}", "R": "{0,1}"}, - "{0,2}": { - "L": "{0}", - "D": "{0}", - "U": "{0}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - "{{0,1,3},{0,2,3},{0,3}}": { - "L": "{{0,1,3},{0,2,3},{0,3}}", - "D": "{{0,1,3},{0,2,3},{0,3}}", - "U": "{{0,1,3},{0,2,3},{0,3}}", - "R": "{{0,1,3},{0,2,3},{0,3}}", - }, - }, - initial_state="{0}", - final_states={"{{0,1,3},{0,2,3},{0,3}}"}, - ) - - def test_make_dfa_for_perm(): assert PinWords.make_dfa_for_perm(Perm.from_string("1032")) == DFA( states={ diff --git a/tox.ini b/tox.ini index 7d88729..db5a6fe 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ [tox] envlist = flake8, mypy, pylint, black - py{37,38,39, 310}, + py{37,38,39, 310, 311}, pypy37 [default] @@ -19,6 +19,7 @@ basepython = py38: python3.8 py39: python3.9 py310: python3.10 + py311: python3.11 pypy37: pypy3 deps = pytest==7.2.0