### fsm

#### about states of finite state machine

```the question is let sigma =(1,2,3,\$). I need to draw its diagram which outputs 1 when sum is >_5. if it is over 5, the amount will be carried over.
Im wondering what would be the state in this case. Can I let A = ive seen 1 B=ive seen 2, C=ive see 3 and D = accepted state?
```
```No, you cannot use just three states. Your FSM must, somehow, keep counting the current sum of the input values so far. The problem is that a FSM has no memory (that would be another kind of automata) so it has to be one state for every possible combination of numbers that evaluate to all possible sums.
That is: you need a state that means ("the current sum is 0").Let that state be state 0. That would be your initial state. Other states would be "the current sum is 1" (state 1), "the current sum is 2" (state 2), .... , "the current sum is 5" (state 5), "the current sum is 6" (state 6), etc (no, you won't need an inifinite number of states, as for example, from state 5, a transition with value 1 leads you again to the state 1.
From state 0, a transition with 1 leads you to state 1. Transition with 2, to state 2 and transition with 3 to state 3. Easy, isn't it?
From state 3, for example, a transition with 1 leads you to transition 4, Transition with 2 to state 5, which is an accept state, and transition with 3 to state 6, which is also an accepted state.
To put another example: from state 6, a transition with 1 leads you to... state 2. That's right: state 6 means that the current sum is 6, which exceeds 5 in 1. So this is like transition 1, but it is an accepted state, so transitions from state 6 go to the same places as transitions from state 1 would go. This will help you building your FSM.
In fact, the larger state number is determined by the largest value you can sum with 1,2 and 3 that overflows 5 for the first time. That would be 1+1+1+1+3 = 7. So you need to define from state 0 to state 7, and of course, a final state when \$ is detected.
```
```You don't need to keep track of the current sum. You just need to keep track of the total sum modulo 5.
One way of doing this is to let your state space be A0, A1, A2, A3, A4, and B0, B1, B2. If you enter an "A" state, you output 0, and if you enter a "B" state, you output 1.
Your state transitions depend on the next digit that you see. For example:
If you are in A1, and the next digit you see is 2, you transition to A3, and output 0.
If you are in A4, and the next digit you see is 1, you transition to B0, and output 1.
If you are in B2, and the next digit you see is 1, you enter A3, and output 0.
If you are in B2, and the next digit you see is 3, you enter B0, and output 1.
In general, suppose you are in state XY, where X is either A or B, and Y is 0, 1, 2, 3, or 4. Let D be the next digit you see. The next state you will enter will be X'Y', where:
X' is A if D + Y < 5.
X' is B if D + Y >= 5.
Y' is D + Y modulo 5.```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization