Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Finite Automaton

NotificationsYou must be signed in to change notification settings

janbican/finite-automaton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Formal Definition

States and symbols are represented by strings.
Transitions are objects of interface { state, symbol, resultState }.
Each state needs a transition for each input symbol. (completeness)

Requirements

Tested with Node.js v16.13.1

Example

Automaton that accepts binary strings that contain an even number of 0s.

alt DFA example

consttransitions=[{state:'even',symbol:'0',resultState:'odd'},{state:'even',symbol:'1',resultState:'even'},{state:'odd',symbol:'0',resultState:'even'},{state:'odd',symbol:'1',resultState:'odd'},]constautomaton=newFiniteAutomaton({  transitions,startState:'even',acceptStates:['even']})console.log(automaton.isAccepting('00'))// trueconsole.log(automaton.isAccepting('10'))// falseconsole.log(automaton.states())// ['even', 'odd']console.log(automaton.alphabet())// ['0', '1']

API

Consider automaton from example above.

automaton.isAccepting('010')// trueautomaton.process('010')// { isAccepting: true, stateSequence: [ 'even', 'odd', 'odd', 'even' ] }automaton.states()// [ 'even', 'odd' ]automaton.alphabet()// [ '0', '1' ]automaton.transitions()// [//  { state: 'even', symbol: '0', resultState: 'odd' },//  { state: 'even', symbol: '1', resultState: 'even' },//  { state: 'odd', symbol: '0', resultState: 'even' },//  { state: 'odd', symbol: '1', resultState: 'odd' }// ]automaton.startState()// 'even'automaton.acceptStates()// [ 'even' ]

[8]ページ先頭

©2009-2025 Movatter.jp