FSA: Creating Machines

Published by bangyen in

Create a finite-state automaton that determines whether a binary number is divisible by five. The finite-state automaton from this challenge can be constructed as follows:

Example FSA

divisible = {
  "S0": ["S0", "S1"],
  "S1": ["S2", "S0"],
  "S2": ["S1", "S2"]
}

Each key is a state, and each value denotes instructions for each type of input. For "S0", the array ["S0", "S1"] indicates that if a 0 is received, the new state is "S0". If 1 is received, the new state is "S1".

Notes

  • Remember to create a dictionary, not a function.
  • In this case, "accept" would mean that the number is divisible by five, whereas "reject" means that it isn't.
  • The starting and accepting states should both be "S0".
  • The automaton should read the digits of a binary number from left to right. For example, the first digit for 26 (0b11010) would be 1, since we ignore the 0b.
Watch a quick demo on how Edabit works.