-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomaton.cs
66 lines (61 loc) · 2.01 KB
/
Automaton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
namespace ProyectoAutomata
{
public class Automaton
{
private const string INITIAL_STATE = "q0";
private const string END_STATE = "q2";
private string state;
public Automaton()
{
state = INITIAL_STATE;
}
public Tuple<string, bool> WalkWithAutomaton(string automatonString)
{
foreach (char currentCharacter in automatonString)
{
switch (state)
{
case "q0":
if (currentCharacter == '1' || currentCharacter == '3' || currentCharacter == '5')
{
state = "q0";
}
else
{
state = "q1";
}
break;
case "q1":
if (currentCharacter == '2' || currentCharacter == '4' || currentCharacter == '6')
{
state = "q1";
}
else
{
state = "q2";
}
break;
case "q2":
if (currentCharacter == '1' || currentCharacter == '3' || currentCharacter == '5')
{
state = "q2";
}
else
{
state = "q1";
}
break;
default:
Console.WriteLine("\nSe ha llegado a un estado inválido");
break;
}
}
// Check last state
if (state == END_STATE)
{
return new Tuple<string, bool>(state, true);
}
return new Tuple<string, bool>(state, false);
}
}
}