-
Notifications
You must be signed in to change notification settings - Fork 0
/
turingmachine1.c
55 lines (51 loc) · 1.78 KB
/
turingmachine1.c
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
///////////////////////////////////////////////////////////////////////////////////////////////
// turing machine ------addition /////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/////// //////// ///////////////////////
/////// /////// ///////
////// ////// //////
////////// /// //////
////// /// ////
/// ////////////
#include<stdlib.h>
int main()
{
char tape[]="B00000000000000001000000B";
int q=0;// state
int i=0;// pointer
int t=0;
int count=0;
while(1)
{
if(q==0&&tape[i]=='B')
{
i=i+1;
}
if(q==0&&tape[i]=='0')
{
tape[i]='B';
i=i+1;
q=1;
}
if(q==1&&tape[i]=='0')
{
i=i+1;
}
if(q==1&&tape[i]=='1')
{
tape[i]='0';
i=i+1;
}
if(q==1&&tape[i]=='B')
break;
}
printf("%s\n",tape);
for(t=0;tape[t]!='\0';t++)
{
if(tape[t]=='0')
count++;
}
printf("%d",count);
getch();
return 0;
}