#include #include #include #include #include #include #include #define CP cprintf #define P printf #define PRIN 0 #define STOP 1 #define TIMES +=8+4*++poz #define RED 12 /* 12 - 15 */ #define CUT1 0 int fd,pren; char ch,name[40]; struct time t2,t3,t4; unsigned j,i,buttom=2,izcom=2,poz=0,line=0,co=2,times=7,s=0,rr=1,lr=0,p=16, pc[40]={2},pf[40]={1},ri[82],flag=0,st[360],li[560],max,ix,ix2,x,t,t1,nova=0, buf[1019]; main() { t1:textbackground(0); textcolor(7); CP(" "); clrscr(); textcolor(RED); P("\n\n\n Think of infinite row of zeros and ones,the program "); P("will try to guess it.\n First give the level of difficulty between "); P("1 and 17,zero means exit.\n The program will give you the first digit"); P(" of it's prognosis.By ");CP("SPACE");P(" you can see the next "); P("digits.\n If the prognosis is not true press ");CP("Enter"); P(" and you will have another.\n You will make computer's task "); P("easier if you give it some beginning of your row.That you can do by "); CP("0 1 Y N");P(".\n ");CP("BACK SPACE"); P(" will help you some times to correct your mistakes.\n By "); CP("Esc");P(" you may return to the instructions and by ");CP("G"); P(" you may continue without seeing the text.\n"); #if STOP P(" If the program thinks "); P("too long you may interrupt it by ");CP("Ctrl-C"); P(".In this case you may lose part of given beginning but you can "); P("recover it by pressing ones ");CP("N");P(" and several times "); CP("Y");P(".\n"); #endif P(" By ");CP("M");P(" you may take out Turing's machine"); P(" which generate the current prognosis and by "); CP("C");P(" to take it away.\n By ");CP("W"); P(" you may write the situation in which you are and by "); CP("R");P(" you can read written one."); e5:gotoxy(1,24); textcolor(7); textbackground(0); CP("HOW DIFFICULT "); s0:gotoxy(15,24); while((ix2=bioskey(0))!=0xb30&&((ix=ix2-0x130)%0x101!=0||ix/0x101>9||ix/0x101<1)); if(ix2==0xb30) ix=0; else ix/=0x101; P("%c",48+ix); s1:if((ix2=bioskey(0))==0xe08) /* B.S.*/ { s3: gotoxy(15,24); P(" "); goto s0; } else if(ix2==0xb30 || ((x=ix2-0x130)%0x101==0&&x/0x101<10&&x/0x101>0)) { ix*=10; if(ix2==0xb30) x=0; else x/=0x101; ix+=x; P("%c",48+x); while((ix2=bioskey(0))!=0xe08 && ix2!=0x1c0d); if(ix2==0xe08) { gotoxy(16,24); P(" "); ix/=10; gotoxy(16,24); goto s1; } goto s2; } else if(ix2!=0x1c0d) goto s1; s2:if(ix>17) goto s3; if (ix==0) exit(1); buttom=2*ix; clrscr(); for (ix=1;ix<40;pf[ix++]=4); pc[0]=2; pf[0]=1; ri[0]=8; #if PRIN gotoxy(1,22); P("1 1|"); for (ix=1;ix<36;ix++) { gotoxy(1+4*(ix/2),22+(ix%2)); P(" |"); } gotoxy(35,2); P("*"); #endif for(ix=1;ix<80;ri[ix++]=0); i=0;izcom=2;poz=0;line=0;co=2;times=7;s=0;rr=1;lr=0;p=16; t4.ti_hour=0;t4.ti_min=0;t4.ti_sec=0;t4.ti_hund=0;flag=0; gettime(&t3); while(times--) { j=(ri[i]&p)?1:0; #if PRIN e8: for(ix=i,t=0,t1=p;t<=lr;t++) { gotoxy(35-t,1); P("%c",(ri[ix]&t1)?'1':'0'); if(!(t1=t1<<1)) { ix=1-ix; t1=1; } } gotoxy(35-t,1); P(" "); gotoxy(36,1); for(ix=i,t=0,t1=p;t>1)) { ix=1-ix; t1=0x8000; } P("%c",(ri[ix]&t1)?'1':'0'); } P(" "); gotoxy(45,2); P("co=%u,times=%u,poz=%u,izcom=%u, ",co/2,times,poz,izcom/2); P("line=%u,s=%u,buttom=%u,lr=%u,rr=%u,p=%u,%u.%u ",line,s,buttom/2,lr,rr,p,ri[0],ri[1]); getch(); #endif e3: switch(pf[co+j]) { case 0: /* ZERO-LEFT */ e1: ri[i]=ri[i]&(0xffff^p); if(!(p=p<<1)) { i=1-i; p=1; } if(rr) rr++; if(lr) lr--; else if (rr>31) goto v2; break; case 1: /* ONE-LEFT */ ri[i]=ri[i]|p; if (!(p=p<<1)) { i=1-i; p=1; } rr++; if(lr) lr--; else if (rr>31) goto v2; break; case 2: /* ZERO-RIGHT */ ri[i]=ri[i]&(0xffff^p); if(!(p=p>>1)) { i=1-i; p=0x8000; } if(lr) lr++; if (rr) rr--; else if (lr>31) goto v6; break; case 3: /* ONE-RIGHT */ ri[i]=ri[i]|p; if(!(p=p>>1)) { i=1-i; p=0x8000; } lr++; if (rr) rr--; else if (lr>31) goto v6; break; default: /* NEW BRANCH */ #if CUT1 if (j==li[poz] || line<=poz) #endif pc[co+j]=0; #if CUT1 else pc[co+j]=2; #endif pf[co+j]=0; st[s++]=izcom; st[s++]=co+j; st[s++]=ri[i]; st[s++]=ri[1-i]; st[s++]=p; st[s++]=lr; st[s++]=rr; st[s++]=times; st[s++]=poz; #if PRIN gotoxy(1+4*(co/2),22+j); P("0 0"); goto e8; #else goto e1; #endif } if(!(co=pc[co+j])) /*ВАДИ 4ИСЛО*/ { if(line<=poz) { v20: ix2=0; e12: ttt(); if (line==poz) { sound(66); delay(50); nosound(); } if (poz<=max) { gotoxy(1+line%80,5+line/80); textbackground(ix2); for(ix=line;ix<=max;CP(" "),ix++); } max=poz; gotoxy(1+poz%80,5+poz/80); if (poz==560) { textcolor(7); textbackground(0); CP("and so on..."); goto e5; } li[poz]=j; ch=(j)?'1':'0'; textbackground(7); textcolor((poz%4)?12:11); cprintf("%c",ch); e9: switch(bioskey(0)) { case 0x3920: /* SPASE */ if((times TIMES)>32000) times=32000; if(flag) { gettime(&t3); goto v5; } break; case 0x0231: /* 1 */ ch='1'; li[line]=1; goto e10; case 0x0b30: /* 0 */ ch='0'; li[line]=0; goto e10; case 0x316e: /* N */ ch=(li[line]=1-li[line])?'1':'0'; goto e10; case 0x1579: /* Y */ ch=(li[line])?'1':'0'; e10: gotoxy(1+line%80,5+line/80); textbackground(0); textcolor((line%4)?RED:11); CP("%c",ch); if (++line>max) max=line; goto e9; case 0x0e08: /* Back Space */ if ((s==0 && line>0) || (s>0 && st[s-1]32000) times=32000; } else { #if STOP if (nova++%2048 || bioskey(1)==0) /* Break */ goto e4; else if (bioskey(0)==0x2e03) /* Ctrl-C */ { line=poz; ix2=7; goto e12; } #endif goto e4; } } } } e4:if(s) /* IF THE STACK IS NOT EMPTY - IT IS BRANCHING. */ { if(pf[st[s-=8]]<3) pf[st[s]]++; else if (pc[st[s]]1279) goto v4; break; case 1: /* ONE-LEFT */ ri[i]=ri[i]|p; if (!(p=p<<1)) { i=(i)?i-1:79; p=1; } rr++; if(lr) lr--; else if (rr>1279) goto v4; break; case 2: /* ZERO-RIGHT */ ri[i]=ri[i]&(0xffff^p); if(!(p=p>>1)) { i=(i==79)?0:i+1; p=0x8000; } if(lr) lr++; if (rr) rr--; else if (lr>1279) goto v4; break; case 3: /* ONE-RIGHT */ ri[i]=ri[i]|p; if(!(p=p>>1)) { i=(i==79)?0:i+1; p=0x8000; } lr++; if (rr) rr--; else if (lr>1279) goto v4; break; default: /* NEW BRANCH */ goto v4; } v8: if(!(co=pc[co+j])) /* Subtracts a number */ { if(line<=poz) goto v20; else { if(li[poz]==j) { if((times TIMES)>32000) times=32000; } else goto v4; } } } v4:flag=0; /* if(i<=lr/16) { for(ix=79+i-lr/16;ix<80;ri[ix++]=0); for(ix=2;ix80) { for(ix=2;ix=t3.ti_hund) { if((t4.ti_hund+=t2.ti_hund-t3.ti_hund)>99) { t4.ti_hund-=100; pren=1; } else pren=0; } else { if((t4.ti_hund+=100+t2.ti_hund-t3.ti_hund)>99) { t4.ti_hund-=100; pren=0; } else pren=-1; } if (t2.ti_sec+pren>=t3.ti_sec) { if((t4.ti_sec+=t2.ti_sec+pren-t3.ti_sec)>59) { t4.ti_sec-=60; pren=1; } else pren=0; } else { if((t4.ti_sec+=60+t2.ti_sec+pren-t3.ti_sec)>59) { t4.ti_sec-=60; pren=0; } else pren=-1; } if (t2.ti_min+pren>=t3.ti_min) { if((t4.ti_min+=t2.ti_min+pren-t3.ti_min)>59) { t4.ti_min-=60; pren=1; } else pren=0; } else { if((t4.ti_min+=60+t2.ti_min+pren-t3.ti_min)>59) { t4.ti_min-=60; pren=0; } else pren=-1; } if (t2.ti_hour+pren>=t3.ti_hour) t4.ti_hour+=t2.ti_hour+pren-t3.ti_hour; else t4.ti_hour+=t2.ti_hour+pren+24-t3.ti_hour; gotoxy(67,1); textbackground(0); textcolor(7); CP("%4dh %02d:%02d.%02d ",t4.ti_hour,t4.ti_min,t4.ti_sec,t4.ti_hund); }