#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<conio.h>
int main()
{
_AX=0x13;
geninterrupt(0x10);
time_t t;
char far*Q=(char far*)0xA0000000L;
char E,D[]=" 123456789";
int a,c,d,f,h,c1,c2,c3,c4,x,y;
int n1[81],n2[81],n3[81];
int N1[9][10],N2[9][10],N3[9][10];
int e[225],g[3],i[81],C[82],X[81],Y[81];
int b[]={5,0,2,0,0,0,0,0,0,
0,0,0,0,6,0,9,0,0,
0,0,0,0,0,0,0,0,0,
0,4,1,0,0,7,0,0,0,
0,0,0,5,0,0,0,6,0,
0,0,5,0,0,2,0,0,0,
0,9,7,0,8,5,0,0,0,
0,0,0,0,0,0,0,3,5,
0,5,4,0,0,0,0,9,6};
for(d=225;d--;)
e[d]=d/15*320+d%15+321;
for(c=c1=0;c1<3;c1++)
for(c2=0;c2<3;c2++)
for(c3=0;c3<3;c3++)
for(c4=0;c4<3;c4++){X[c]=12+c%9*2;
Y[c]=4+c/9*2;
n1[c]=3*c1+c2;
n2[c]=3*c3+c4;
n3[c]=3*c1+c3;
i[c]=x=8*X[c]+2560*Y[c]-4173;
for(d=16,a=0;a<=(c2+c4<1)+(c<1);a++,d*=3,x-=321)
for(f=0;f<=a;f++)
for(h=d+f,y=0;y<=h;y++)
*(Q+x+y)=*(Q+x+320*y)=*(Q+x+y+320*h)=*(Q+x+320*y+h)=7;
printf("%c[%u;%uf%c",27,Y[c++],X[c],D[b[c]]);
}
Inicio:
for(c=81;c--;N1[x][y]=N2[x][y]=N3[x=c/9][y=c%9+1]=0)
for(d=b[c]?225:0;d--;)
*(Q+i[c]+e[d])-=*(Q+i[c]+e[d])==1;
g[0]=g[1]=g[2]=E=c=0;
while(kbhit()) getch();
while(E!=13){for(d=225;d--;)
*(Q+i[c]+e[d])+=!*(Q+i[c]+e[d]);
if(E<48||E>57) E=getch();
else{printf("%c[%u;%uf%c",27,Y[c],X[c],D[b[c]=E-48]);
E=77;
}
if(E==27) return 0;
for(d=225;d--;)
*(Q+i[c]+e[d])-=*(Q+i[c]+e[d])==1;
c+=E==77&&c<80;
c-=E==75&&c>0;
c+=9*(E==80&&c<72);
c-=9*(E==72&&c>8);
if(E==32) E=48;
}
for(c=81;c--;)
if(a=b[c])
if(N1[n1[c]][a]+N2[n2[c]][a]+N3[n3[c]][a])
printf("%c[%u;%uf%c",27,Y[c],X[c],D[b[c]=0]);
else{N1[n1[c]][a]=N2[n2[c]][a]=N3[n3[c]][a]=1;
g[c/27]++;
for(d=225;d--;)
*(Q+i[c]+e[d])+=!*(Q+i[c]+e[d]);
}
for(h=y=0;y<3;y++){for(a=x=0;x<2;x++)
if(g[a]<g[x+1]) a=x+1;
for(d=0;d<27;d++)
if(!b[c=27*a+d]) C[++h]=c;
g[a]=-1;
}
f=++h>1;
t=time(NULL);
while(f)
if(f<h){if(a=b[c=C[f]])
N1[n1[c]][a]=N2[n2[c]][a]=N3[n3[c]][a]=0;
while(++a<10&&N1[n1[c]][a]+N2[n2[c]][a]+N3[n3[c]][a]);
if(a<10) N1[n1[c]][a]=N2[n2[c]][a]=N3[n3[c]][a]=1;
gotoxy(X[c],Y[c]);
printf("%c",D[b[c]=a%10]);
f+=a<10?1:-1;
}
else{printf("%c[23;11f%.f%c ",27,difftime(time(NULL)+1,t),34);
printf("Pulse una tecla\r");
while(kbhit()) getch();
if(getch()==27) return 0;
printf("%c[2K",27);
f--;
}
goto Inicio;
}
Comentarios sobre la versión: 2,5 (0)
No hay comentarios