Skip to content

goodylabs/backend-dev-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Finite State Machine Test

Description:

Create a finite automaton that has three states. Finite automatons are the same as finite state machines for our purposes.

Our simple automaton, accepts the language of A, defined as {0, 1} and should have three states, q1, q2, and q3.

q1 is our start state. We begin reading commands from here. q2 is our accept state. We return true if this is our last state.

q1 moves to q2 when given a 1, and stays at q1 when given a 0. q2 moves to q3 when given a 0, and stays at q2 when given a 1. q3 moves to q2 when given a 0 or 1.

Our automaton should return whether we end in our accepted state, or not (true/false.)

Here's an example.

var a = new Automaton();
// Do anything you need to set up this automaton's states.
var isAccepted = a.readCommands(["1", "0", "0", "1", "0"]);

We make these transitions based on the input of ["1", "0", "0", "1", "0"],

1 q1 -> q2 0 q2 -> q3 0 q3 -> q2 1 q2 -> q2 0 q2 -> q3 We end in q3, which is not our accept state, so return false.

The input of ["1", "0", "0", "1", "0"] would cause us to return false, as we would end in q3.

I have started you off with the bare bones of the Automaton class, as seen in ./src/Automaton. The task is to complete the implementation.

You will have to define how the Automaton stores it's state, and transitions between states based on the commands passed to readCommands.

As an aside, the automaton accepts an array of strings, rather than just numbers, or a number represented as a string, you may assume you will only be passed valid inputs.

Acceptance tests are included in the test file. Do not modify these. When all these tests pass this means your implementation is correct.

setup

You will need node v4 installed.

Clone this repository.

Go into the fsm/ folder and run:

nvm use
npm install

To run the tests do:

npm run test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published