A complete deterministic finite automaton is a machine, with some states. Each state in the automaton has, for each character in the alphabet, a pointer to a state (not necessarily a different one). The automaton starts at some state, and then reads a string, character by character. For each character, the automaton moves to the pointer of its current state for the character.
For a given automaton, a synchronizing word is a string which will bring the automaton to the same state, regardless of which state it started in.
For example, the following automaton:
Has 0100
as a synchronizing word, which synchronizes all states to 2.
Not all automata have a synchronizing word. For example, the following automaton:
Doesn't have any synchronizing word - if the length of the string is even then 0 will stay in 0 and 1 will stay in 1, and if it's odd they will swap - in any case, they won't go into the same state.
Your challenge is to write the shortest program you can that checks, given a complete automaton over an alphabet with two characters, if there exists a synchronizing word for it.
Test cases
Using a 0-indexed, 2Xn array.
[[0, 1], [0, 1]] -> true
[[1, 1], [0, 0]] -> false
[[0, 0], [1, 1]] -> false
[[4, 1], [0, 3], [0, 0], [0, 1], [4, 3]] -> true
[[2, 1], [3, 4], [0, 4], [2, 1], [0, 3]] -> true
[[4, 4], [0, 4], [2, 1], [0, 3], [0, 0]] -> false
[[8, 5], [0, 8], [0, 0], [8, 2], [2, 6], [5, 2], [3, 8], [7, 3], [8, 4], [3, 0]] -> true
[[9, 2], [8, 4], [2, 5], [6, 9], [8, 9], [9, 5], [4, 0], [4, 2], [0, 7], [2, 1]] -> true
[[5, 0], [3, 7], [9, 2], [9, 0], [1, 8], [8, 4], [6, 5], [7, 1], [2, 4], [3, 6]] -> true
[[5, 1], [4, 9], [8, 1], [8, 6], [2, 3], [7, 0], [2, 3], [5, 6], [4, 9], [7, 0]] -> false
[[6, 3], [1, 1], [7, 5], [7, 1], [4, 5], [6, 6], [4, 6], [5, 1], [3, 4], [2, 4]] -> false
Rules
- You can use any reasonable I/O format. In particular, any of the following input methods are allowed:
- A map, multidimensional array, or array of maps, denoting, for each state and character, to which state the automaton transitions. The states can be either 0-indexed or 1-indexed.
- Any builtin directed graph object which can support multiedges, self-loops, and labeled edges.
- Any builtin DFA object.
- You can choose any two characters to be the alphabet.
- You can output any two distinct values, or a truthy/falsey (or reversed) value in your language.
- You may not assume Černý's conjecture (which states that if there exists a synchronizing word, there must be one of length \$(n-1)^2\$).
- Standard loopholes are disallowed.
a
means: if the state iss
and you readc
, go to statea[s][c]
\$\endgroup\$