As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [state-machine]

A state machine is a model for designing systems which change based upon their current state and what input they receive.

Filter by
Sorted by
Tagged with
3 votes
0 answers
60 views

"Academic interest" implementation of a Finite State Machine

Context I'm playing around the concept of a Finite State Machine. While I understand the basic principles behind it, I want to implement a simple, yet generic class which could be reused in the ...
Igor Soloydenko's user avatar
3 votes
2 answers
1k views

DFA creation from string

I have fairly simple Python 3 code that creates a DFA from a string. It works great, but I believe it can be made more efficient. There are a total of 3 loops: First iterates over the string Second ...
theblindprophet's user avatar
4 votes
1 answer
779 views

Mars Rover problem in J

I've written an implementation of the "famous" Mars Rover simulation, (another question on this) whose problem statement is this: The first line of input is the upper-right coordinates of ...
Daniel Lyons's user avatar
1 vote
1 answer
912 views

Stack-based state machine

Is everything alright with this code? What can I add to it? state.h: ...
nuke_bird's user avatar
5 votes
2 answers
571 views

Alternative to nonlocal for local variables in a function with nested functions in Python

Introduction for future readers I posted the code below in the hope that it would be a good example to discuss the topic "Alternative to nonlocal for local variables in a function with nested ...
nilo's user avatar
  • 507
2 votes
0 answers
66 views

Time-dependent state machine with two outputs

Given a class BasicDataFeed whose purpose is to feed questions and answers into an artificial neural network, which is tested in a non-negotiable manner as follows: ...
Seanny123's user avatar
  • 1,463
14 votes
2 answers
16k views

Very simple finite state machine

I have beginner knowledge of C++ and using that and some self dummy design I came up with the above implementation. The FiniteStateMachine here first asks for the ...
Abhinav Agarwal's user avatar
2 votes
1 answer
2k views

Tennis-Refactoring-Kata through OOP

I was trying to solve Tennis-Refactoring-Kata. This seems quite hard at startup but, through use os OOP it can be deeply refactoring using just a single if. My ...
BAD_SEED's user avatar
  • 121
6 votes
0 answers
193 views

Character-based transitions (part of a lexer)

As part of my prep for the Code Review community-challenge (which looks like it will be Write your own programming language), I've been working on an LL(1) lexer generator in Rust. Yes, lexer ...
CAD97's user avatar
  • 1,934
0 votes
2 answers
274 views

Stateful implementation of TicTacToe

I made a TicTacToe implementation using State pattern in Java. I was wondering if this could ...
yadav_vi's user avatar
  • 486
2 votes
1 answer
271 views

Regex to DFA parser in Dart

I've created a Regex to DFA parser, using Thompson's construction algorithm and epsilon-reduction. Here is the code: builtins.dart: ...
Qwerp-Derp's user avatar
5 votes
1 answer
473 views

Designing posts: state machine

In the Object-Oriented Design Pattern Implementation chapter of the second edition of The Rust Programming Language, the basic code structure is given and it suggests trying to add features: This ...
Ashish Negi's user avatar
2 votes
0 answers
92 views

STTCL FSM framework based on the GoF State Pattern, Part III: Policy based design of higher level State Machine constructs

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
πάντα ῥεῖ's user avatar
3 votes
0 answers
61 views

STTCL FSM framework based on the GoF State Pattern, Part II: Abstraction of asynchronous/concurrency features

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
πάντα ῥεῖ's user avatar
8 votes
0 answers
348 views

STTCL FSM framework based on the GoF State Pattern, Part I: The basic interfaces

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
πάντα ῥεῖ's user avatar
1 vote
1 answer
46 views

How to refactor / re-architect the components/state here in ui-router app [closed]

https://plnkr.co/edit/bOZW1a9u62W1QA6cYjYj?p=preview My goal has been to separate the Dashboard states from the Feed state. ...
Leon Gaban's user avatar
6 votes
1 answer
93 views

Arduino controller to control the backlighting of a gear selector

Background The gear selector on a car allows the driver to select which state the transmission should be in. In the example picture, one of the five letters (P, R, N, D & S) lights up to ...
Zaid's user avatar
  • 163
8 votes
3 answers
2k views

Efficient data-driven finite state machine

In creating this answer to a recent question, I thought I might write a fully worked example that implements a finite state machine in C. The purpose is to implement the following function: ...
Edward's user avatar
  • 65k
1 vote
1 answer
153 views

SafeBox StateMachine implemented with Enums

does someone has any opinions about this SafeBox StateMachine? ...
Arigatonic's user avatar
3 votes
1 answer
246 views

Defusing a bomb using a state machine

This code is a solution for /r/daily_programmer #293. The idea of this challenge is, you are given input in the form of colored wires: ...
tijko's user avatar
  • 638
5 votes
1 answer
85 views

Logon state management

I'm in the process of writing a simple text based MUD. First up is making sure that it's possible to create new players / logon with existing players. Since everything is text based, there are ...
forsvarir's user avatar
  • 11.6k
1 vote
1 answer
47 views

Handling workflow rules for a job application process

For some reason I always have a negative feeling towards having many if statements in my JavaScript functions. But I've got some code that is processing an object ...
Jeremy H.'s user avatar
  • 141
4 votes
1 answer
256 views

Time-dependent state machine

I keep having to write state machines that depend on time for various experiments I run and I'd like to know how to write them better. This state machine is for training a neural network by feeding in ...
Seanny123's user avatar
  • 1,463
10 votes
1 answer
8k views

Event-driven finite state machine DSL in Kotlin

I wrote a DSL for defining a finite state machine. My robotics team wants to use a state machine to manage the state of the subsystems on our robot, like the arms, drive train, lifter, etc. Each ...
Roth's user avatar
  • 103
7 votes
1 answer
2k views

Implementation of tokenizer object and finite state machine in C

I was given an assignment to create an implementation of a tokenizer object (by object, I mean a struct with associated functions that operate on instances of the struct). This tokenizer retrieves ...
JRTN's user avatar
  • 111
5 votes
1 answer
132 views

UTF8 Codepoint decode and length v.2

This is the complete rewrite of a function to decode an UTF-8 codepoints and return the encoding length (or 0 if the codepoint is ...
Remo.D's user avatar
  • 335
0 votes
1 answer
57 views

Controller method to modify Active Directory, other systems, and send notification with error handling

I have to handle an Action (Modify) about my web application. The app working with SMTP Email, ActiveDirectory, External System (...
PreguntonCojoneroCabrón's user avatar
6 votes
2 answers
3k views

Simple ini file parser

The below is a C++ parser for a reasonably simple INI grammar (although my understanding is that there isn't an official spec as such). My grammar is roughly: ...
cloakedlearning's user avatar
3 votes
0 answers
429 views

Linear finite state machine in ES6

I would love some feedback on my linear finite state machine. I say linear, as it can only handle one state at a time. I am also giving my method of how I -work- with the state machine, as I would ...
bitten's user avatar
  • 181
3 votes
0 answers
39 views

Backbone.model based state machine

I have created a class to keep track of some internal states. You can see it as a very simple implementation of a state machine ...
Anthony Kong's user avatar
10 votes
1 answer
341 views

Parse regular expression

Task: This function searches given null terminated string pStr by given subset of regular expression pMatch. Return value is ...
loudking's user avatar
  • 101
7 votes
1 answer
2k views

Simulate Turing machine

I have written this code to simulate a Turing machine and wonder what could be improved. In particular, the --tape.end() seems a bit dodgy. ...
Andrew Hickman's user avatar
0 votes
1 answer
4k views

Table-Driven Finite State Machine

I'm writing a finite state machine based on a transition table in C++ 14. My code so far looks like: ...
tobspr's user avatar
  • 111
2 votes
1 answer
221 views

NFA and DFA implementation

Can you review my F# code and point out some insights about it? What I want to know, in order of relevance: Avoid so much common code between DFA and NFA. I want to make something more generic, ...
Gabriel's user avatar
  • 1,053
8 votes
1 answer
9k views

Deterministic finite automaton in Java

Formally, a deterministic finite automaton is a 5-tuple \$M = (Q, \Sigma, \delta, q_0, F)\$, where \$Q\$ is the set of all possible states \$\Sigma\$ is the alphabet \$\delta \colon Q \times \Sigma \...
coderodde's user avatar
  • 26.7k
4 votes
1 answer
479 views

Finite state machine written in OCaml to test for the sequence 0,1

I got inspired by Stack Overflow to build a simple state machine which can test if a sequence contains 0,1. I have two questions: How can I get rid of line ...
grigoriytretyakov's user avatar
2 votes
1 answer
943 views

Building thermostat state machine in Python

I used a Raspberry Pi and Adafruit LCD with buttons to build a small thermostat for my house. This is the hardware I used to you can imagine how the button and the code work: https://www.adafruit.com/...
Pitto's user avatar
  • 799
5 votes
2 answers
128 views

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

I am solving a puzzle (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) and have written following Python code....
h_t's user avatar
  • 51
6 votes
1 answer
401 views

Chat room using GenServer

It seems odd that state must be passed around all the time. Can't State module hold itself, so I could do something like ...
roberts's user avatar
  • 61
11 votes
2 answers
201 views

Using state transitions to filter C comments

This is my second attempt at K&R 1-23, Write a program to remove all comments from a C program. Don't forget to handle quoted strings and character constants properly. C comments don't nest....
ivan's user avatar
  • 795
4 votes
1 answer
797 views

Asynchronous start/stop state transitions

I have a third-party object with asynchronous start and stop methods. Each start and stop may fail with exception. The object is not re-entrant, i.e. I can only call its start or stop method after the ...
Soonts's user avatar
  • 253
5 votes
1 answer
2k views

Model of an mp3 player with state and prototype design patterns

After reading about design patterns in general, I decided to try and incorporate them in an actual program. I chose a State machine for my first exercise, or, more concretely, an MP3 player. The ...
Stefan Rendevski's user avatar
13 votes
2 answers
282 views

Vending Machine in Idris

Type Driven Development with Idris demonstrates how Idris can be used to build a Finite State Machine for a vending machine. Please critique my implementation. I'm new to dependent types, so I'm not ...
Kevin Meredith's user avatar
9 votes
5 answers
3k views

Turing Machine in C#

I've tried designing a Turing Machine model, it works quite well, however I think it could be confusing to maintain on in the future, and I'm not sure what of best practices. Can I get some feedback ...
WizardOfMenlo's user avatar
1 vote
1 answer
134 views

Node.js drawing game based off of my state diagram

I really want to have a nice design pattern for my Node.js project. This is my state diagram. As I'm coding this, I'm wondering if it's better to separate state logic from the class? So instead I ...
Daniel Jacobson's user avatar
3 votes
1 answer
315 views

POP3 message downloader using state machine processor

This simple program uses a socket class I wrote, class socket, to retrieve a users pop3 emails and print to stdout. I would like feedback on the socket class and the code to download the pop3 emails. ...
arcomber's user avatar
  • 2,443
3 votes
2 answers
710 views

Solving game state with polymorphism

I've been working on a small game as a hobby, and I've been having trouble finding a good way to control the state of the game that could scale easily. I couldn't find a solution that I felt was ...
Brian's user avatar
  • 151
5 votes
3 answers
5k views

State machine implementation

I have written a simple state machine. Comments and feedback are welcome. ...
cslrnr's user avatar
  • 275
4 votes
0 answers
995 views

C++ Finite State Machine - follow-up

This question is a follow-up from Object Oriented Finite State Machine. I vastly improved commenting and followed the suggestions from the answer. Additionally, I improved my tests and did some more ...
Justin's user avatar
  • 3,265
2 votes
1 answer
1k views

Object Oriented Finite State Machine

I wrote a little library for myself: implementing a generic finite state machine. I will be using this library in class assignments. I clearly have little understanding of C++ templates because most ...
Justin's user avatar
  • 3,265