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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
6
votes
Implementation of tokenizer object and finite state machine in C
Don't Repeat Yourself (DRY)
...
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 ...
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 ...
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:
...
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 ...
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 ...
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 <...
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 ...
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 (...
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 ...
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 ...
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 ...
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'...
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 ...
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, ...
4
votes
Accepted
Efficient data-driven finite state machine
Nice work.
On findWeekdayDate() return, I'd expect a value that is enumerated like ...
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 ...
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 ...
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 ...
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 ;: ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
state-machine × 140c++ × 33
python × 18
java × 16
design-patterns × 15
c# × 12
c × 12
object-oriented × 11
javascript × 10
parsing × 10
beginner × 9
state × 9
python-3.x × 8
c++11 × 8
rust × 8
game × 7
strings × 5
performance × 4
algorithm × 4
interview-questions × 4
regex × 4
ruby × 3
haskell × 3
ecmascript-6 × 3
template × 3