14 votes

Very simple finite state machine

using namespace std Don't use using namespace std. It's considered bad practice. Consistency Use a consistent coding style. ...
Zeta's user avatar
  • 19.2k
10 votes
Accepted

Deterministic finite automaton in Java

Java 8 constructs The following function.putIfAbsent(startState, new HashMap<>()); function.get(startState).put(character, goalState); can be simplified ...
Tunaki's user avatar
  • 9,243
10 votes
Accepted

Event-driven finite state machine DSL in Kotlin

I'd design the StateMachine differently. The StateMachine does not need to know about all the possible Transitions between the States. All the StateMachine should care about is the current State it ...
D3xter's user avatar
  • 281
10 votes
Accepted

The parking machine implementation

Not a finite state machine The state machine in the posted code has infinite states. This is caused by the recursive calls of get_coin and ...
janos's user avatar
  • 111k
9 votes
Accepted

Simple tokenizer v2 - reading all matching chars at once

MatchDelegate Much as I love .NET's nominal delegates, I almost always regret using a delegate rather than an ...
VisualMelon's user avatar
  • 7,421
8 votes

Turing Machine in C#

I would store the value to write directly in the Instruction. That way you don't need the if-else in ExecuteInstruction. Instead ...
ratchet freak's user avatar
7 votes

The parking machine implementation

Given a state machine p which has initial state s and final state f, then it can only accept 0, 5, 10, 20 as inputs. This can be represented graphically as such: Therefore, the machine must continue ...
alexyorke's user avatar
  • 1,181
6 votes

Turing Machine in C#

I don't think you should have constructors that don't take a List<ControlCard> as parameter. It doesn't have any value since this way the ...
IEatBagels's user avatar
  • 12.4k
6 votes

Implementation of tokenizer object and finite state machine in C

Don't Repeat Yourself (DRY) ...
mdfst13's user avatar
  • 21.4k
6 votes
Accepted

C++ CLI Console Menu Statemachine

Use a constructor to initialize class variables Your function buildMenu() looks like it is just initializing all the members of a class ...
G. Sliepen's user avatar
  • 50.6k
6 votes

Simple tokenizer v1 - reading char by char

This isn't exhaustive, because I don't have much time now, so I might add some more later. As I said in a comment, I don't buy the idea of looping over one char at a time: it's not documented that ...
VisualMelon's user avatar
  • 7,421
5 votes
Accepted

Simulate Turing machine

I believe you're looking for std::prev: std::prev(tape.end()); The linked page even states the exact comparison of the two: ...
Jamal's user avatar
  • 34.9k
5 votes

Solving game state with polymorphism

I see some things that may help you improve your program. Fix your includes Case matters to a C++ compiler, so when you write #include <IOStream> it is not ...
Edward's user avatar
  • 65.3k
5 votes

Using state transitions to filter C comments

In all, this looks like pretty solid code. I have just a few suggestions that may help you improve your code. Use an enum for related constants The states are ...
Edward's user avatar
  • 65.3k
5 votes

Finite state automata

Just reviewing DFA. There are no docstrings. What does an object belonging to this class represent? What arguments do I pass to the constructor? What does the <...
Gareth Rees's user avatar
  • 49.6k
5 votes

Turing machine schoolwork

Some grist for the mill: When variables will not be reassigned, it's helpful to declare them as final to reduce cognitive load on the reader. When using the ...
Eric Stein's user avatar
  • 6,494
5 votes
Accepted

Simple tokenizer v1 - reading char by char

State Machine Review This is an interesting, yet unorthodox implementation of a state machine. Your states are actually transitions. You don't really have a state, since the state machine (...
dfhwze's user avatar
  • 13.9k
5 votes

Simple tokenizer v2 - reading all matching chars at once

General thoughts You have managed to create a somewhat elegant API that balances between a state machine pattern and a regex engine. This is reusable for small and context-free use cases, but will ...
dfhwze's user avatar
  • 13.9k
5 votes

Scalable design of a system with multiple state machines, where valid state transitions depend on the state of other machines

This doesn't have to be complicated. Definitely avoid Approach 1 - having a dedicated class for state combinations is not a good idea. Follow vaguely Approach 2, but Do not have a ...
Reinderien's user avatar
5 votes

Sequence state machine

First, you should follow the Java naming conventions. Second, don't shorten names just because you can. Example, what does "Proc" stand for? Procedure? Processor? Even if names become ...
Bobby's user avatar
  • 7,712
4 votes

Turing Machine in C#

Remove the extra this. whenever it isn't required. It makes your code cleaner and anyone writing in a good IDE can put their mouse over the variable to see where it'...
Caleb707's user avatar
  • 141
4 votes

Finding if there exists an input for a given automata for which no matter what the starting state is, final state would be same everytime

There's no need to define both __str__ and __repr__ for Node when they're both the same ...
SuperBiasedMan's user avatar
4 votes
Accepted

Time-dependent state machine

1. (Possible) bugs There are several problematic aspects of the code in the post. However, it is impossible for me to tell whether these really indicate bugs, because the code has no documentation, ...
Gareth Rees's user avatar
  • 49.6k
4 votes
Accepted

Efficient data-driven finite state machine

Nice work. On findWeekdayDate() return, I'd expect a value that is enumerated like ...
chux - Reinstate Monica's user avatar
4 votes

Efficient data-driven finite state machine

This was quite fun to read and to figure out how it works. It took me a while to understand the control flow, which is my main point of critisism. I rearranged it a bit so that, at least in my ...
mkrieger1's user avatar
  • 1,694
4 votes
Accepted

Arduino controller to control the backlighting of a gear selector

I see some things that may help you improve your code. The Arduino language isn't C The language used for the Arduino isn't quite C and isn't quite C++, so if your goal is "to learn C," you might ...
Edward's user avatar
  • 65.3k
4 votes

Very simple finite state machine

Zeta's answer is excellent. I'd like to point out a few additional things. First, remember that you can use = default to implement a boilerplate constructor, such ...
Adrian McCarthy's user avatar
4 votes
Accepted

Mars Rover problem in J

I applaud any use sequential machine. A primitive that simulates a state machine... fruit only the tree of J could produce... why resist? So while in that way ;: ...
Jonah's user avatar
  • 4,340

Only top scored, non community-wiki answers of a minimum length are eligible