I have this picture of a state diagram and have to calculate the value of x after a few events. The events are e1-e2-e2-e2-e2
The x would be 2 in the beginning.
First event is e1, so I think it would become 4 after that event.
Next is e2 and I was wondering because the exit is x=x-1, so would it go to state B, because it is less that 4, or C because it was 4, but became 3 in the exit?
And lets suppose it goes to B, and becomes 5, and we do e2 again. Would nothing happen because the only possibility is x>5 and it is equal to 5?
Assuming that the guard between A and C is x>=4 (since there is no e defined) I made a small transition table:
So the final state should be B and X is 11.
In UML state machines, the guards are evaluated, when beeing in the original state. I.e., when receiving e2 the first time, x is 4 and thus you take the transition to C, unser the assumption that e is x (otherwise it doesnt make sense) . After you decided going to C, and thus leave A, you aubstract 1 from x due to the exit ocndition. When beeing in C, you can change B by trigger of e2, which is unguarded (the guard x>5 belongs to the transition from B to C). Now x is 6, as you add 3 due to the entry condition. Then you receive the next e2 and transide to B, where you add 1, so x is now 7. When receiving the next e2, you check the guard on the transition to C, which demands that x is greater 5, which holds. So lets go to C and execute the entry action once again. So x is now 10. Then you get one more e2, so the state changes to C and its entry action is executed, thus x is 11.
So after the execution of the given events, x is 11 and the statemachine is in state B.
Related
I got stuck by a simple box puzzle in a mobile game called Genshin impact. Here is the scenario:
There are n boxes in front of the player. Each box has one side marked in blue, and the player has to turn one box at a time until all the blue sides facing the player. (There are some relationships between boxes, for example, if you turn box A, the boxes C and D will turn as well). The box can only be turned horizontally so we only need to consider 4 sides.
I normally apply brutal force to solve this kind of a puzzle but now I am curious about the hidden logic.
Here is a concrete example:
n = 5 (We have 5 boxes in front of us) named A, B, C, D, E
if you turn A, C will move as well A->C
if you turn B, A, C will move B->(A,C)
if you turn C, A, E will move C->(A,E)
if you turn D, C, E will move D-> (C,E)
if you turn E, C will move E-> C
All the turns are synced with the same pace, which means turn B one unit, A, C will turn one unit as well. To simply the scenario, in this game, the player turns one unit at a time and always turns clockwise.
The initial state is:
A = 3
B = 0
C = 2
D = 1
E = 2
What are these numbers represent? when the blue mark is in front of me, I assign that position 0, the blue mark to the left side, I assign that position 1, and so on. So the number 2 means the blue mark is in the back. Therefore, we can use position number mod 4 to determine the blue mark's location.
Any ideas? Any coding simulation or mathematic interpretation will be greatly appreciated.
Here is a link to the K map: http://tma.main.jp/logic/logic.php?lang=en&type=eq&eq=%28%7EA%7EBC%7ED%29+%2B+%28%7EA%7EBCD%29+%2B+%28%7EAB%7ECD%29+%2B+%28%7EABCD%29+%2B+%28A%7EB%7EC%7ED%29+%2B+%28A%7EB%7ECD%29+%2B+%28A%7EBC%7ED%29+%2B+%28A%7EBCD%29+%2B+%28AB%7EC%7ED%29+%2B+%28AB%7ECD%29+%2B+%28ABC%7ED%29+%2B+%28ABCD%29
I've also attached the screenshot below.
My questions is, if the groups should be large enough, why the highlighted area is not considered but only a subset is considered to get BD instead of D?
Thank you in advance.
The groups should be "large enough" so they cancel a variable X and NOT X out. This only works when a complete X or NOT X is hit by your selection. When you select your six selected cells you will hit the AD area completely, but not the A'D area. This means you cannot cancel them out and get just D as you want to. When you hit the whole AD and A'D area this has the meaning as: "Well, the condition depends on D and is totally unrelated to the value of A."
When written as boolean algebra you get:
AD OR A'D
(A OR A') AND D
( true ) AND D
D
That would be the goal. But since you don't cover the whole A'D area you can't make this simplification here.
To check if you have selected the correct numbers of cell in a selected area, the numbers of cells must be a value of power of 2. So it must be one of 1, 2, 4, 18, 16, ...
In this case you have the regions:
A (2*4=8)
BD (2*2=4)
B'C (2*2=4, notice how the region "wraps" around the edge of the K-map)
Keep in mind that the result for A'B'C'D is false, not true. But when you have just D in your boolean algebra like in A+D+B'C, the result would be true.
I am having difficulty in understanding a key point in how count to infinity can occur.
Let us say we have a network
A-B-C-D-E
The cost for each link is 1.
According to Tanenbaum,
when A goes down, B will update its cost towards A as infinity. But B receives an advertisement from C which says "I can reach A with a cost of 2". Now, B can reach C with a cost of 1, so it updates the distance to A as 3.
In the next part I have a problem.
He says,
now C notices that both its neighbors can reach A with a cost of 3.
"So C will update distance to A as 4"
Why does this happen? Because already C thinks it can reach A by a cost of 2.
By the Bellman Ford equation, this cost is lesser than the cost 3+1=4. Why shouldn't it simply keep 2 as the distance rather than changing it to 4?
Because the previous route from C to A was via B (with cost 2). Since now B is announcing to C a new route with cost 3, C has to update the cost to 4. This could happen in a scenario when the path from B to A has changed, and has a higher cost; C has to use the new cost.
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.
The question is:
Write a DFA to recognize the regular language L1 = {w ={1,2,3} | the sum of the digits in w is divisible by 5}
More so, based on the input 1 , 2 , 3 the remainder of the sum should be 0 when dividing by 5. I am almost done this question but I can't seem to understand how to find the correct remainder when the input is 3. Since I have done most of the work I have a picture that I will link so you can understand where I am stuck.
Start State: q0
Accept State: q0
My problem is how to control the input 3 so the choices for it will lead to a remainder of 0 when dividing by 5.
Here's some hints:
Have one state for each possible remainder modulo 5.
Given state x and character c, have the transition take you to state (x + c) modulo 5.
Think about what your accept state would be given the meaning of your states.
Hope this helps!