3 ms·
that can be compiled to a state machine where a decision to switch states is taken based on current character only, and when all input is consumed you are eithe
by edwintorok 11y ago
that can be compiled to a state machine where a decision to switch states is taken based on current character only, and when all input is consumed you are either in an accepting or rejecting state. In your case I think it only needs 2 states: state 0 moves to state 1 when it sees an A, and state 1 moves to state 0 when it sees either A or B.
For your string it'll be in state 0 when it sees a B and thus rejects it.
- thaumasiotes 11y ago┌┐ ↓│ ┌────┴┐ ┌─→│ │←──┐ │ └─────┘ │ ╔════╧═╗ ┌──┴──┐ ├─→║ ╟───A──→│ │ ╚══════╝ └─┬───┘ ↑ │ └─────A,B────┘ Three states if you want to process the whole input. If your model is "reject when you fail to find an appropriate transition" rather than "reject if, after processing the string, you're in a reject state", then you don't need the failure trap and you can do it in two states. Backtracking is definitely not required, nor helpful.
- hobs 11y agoThat diagram is quite pretty, did you just hand code it?
- thaumasiotes 11y agoYeah, all manual. :/ http://unicode-table.com/en/blocks/box-drawing/ http://unicode-table.com/en/blocks/box-drawing/ http://unicode-table.com/en/sets/arrows-symbols/ http://unicode-table.com/en/sets/arrows-symbols/