Author: Dann Corbit
Date: 17:25:03 06/07/04
Go up one level in this thread
On June 07, 2004 at 20:20:18, Dieter Buerssner wrote:
>On June 07, 2004 at 19:32:11, Dann Corbit wrote:
>
>>Which accounts for the difference
>
>You were 5 minutes faster. Following C-Prog (really a hack):
>
>#include <stdio.h>
>#include <string.h>
>
>int main(void)
>{
> int np[5];
> int i,lineno=0,e,ok=0,fb;
> char buf[1024];
> static int pos[5*5*5*5*5*5*5*5]; /* Will need 32 bit compiler. */
> unsigned int idx;
> while (fgets(buf,sizeof buf, stdin))
> {
> lineno++;
> if (strlen(buf) < 8)
> continue;
> for (i=0; i<5; i++)
> np[i] = 0;
> idx = 0;
> e = 0;
> for (i=0; i<8; i++)
> {
> switch(buf[i])
> {
> case 'n': case 'N': np[0]++; idx*=5; break;
> case 'b': case 'B': np[1]++; idx = idx*5+1;
> if (np[1] == 1)
> fb = i;
> else
> {
> if (((i^fb) & 1) != 1)
> {
> fprintf(stderr, "Same color Bs in %s at line %d\n", buf, lineno);
> e = 1;
> }
> }
> break;
> case 'r': case 'R': np[2]++; idx = idx*5+2;
> if (np[2] == 2 && np[4] != 1)
> fprintf(stderr, "king not between rooks in %s at line %d\n", buf,
>lineno);
> break;
> case 'q': case 'Q': np[3]++; idx = idx*5+3; break;
> case 'k': case 'K': np[4]++; idx = idx*5+4;
> if (np[2] != 1)
> {
> fprintf(stderr, "king not between rooks in %s at line %d\n", buf,
>lineno);
> e = 1;
> }
> break;
> break;
> default:
> fprintf(stderr, "unknown piece in %s at line %d\n", buf, lineno);
> e = 1;
> break;
> }
> }
> for (i=0; i<3; i++)
> if (np[i] != 2)
> {
> fprintf(stderr, "piece %d = %d (!= 2) in %s at line %d\n", i, np[i],
>buf, lineno);
> e = 1;
> break;
> }
> if (np[3] != 1)
> {
> fprintf(stderr, "wrong number of queens %d in %s at line %d\n", np[3],
>buf, lineno);
> e=1;
> }
> if (np[4] != 1)
> {
> fprintf(stderr, "wrong number of kings %d in %s at line %d\n", np[4], buf,
>lineno);
> e=1;
> }
> if (pos[idx] != 0)
> {
> fprintf(stderr, "Position %s at line %d already seen at line %d\n", buf,
>lineno, pos[idx]);
> e=1;
> }
> pos[idx] = lineno;
> if (e==0)
> ok++;
> }
> printf("%d lines processed, %d pos ok\n", lineno, ok);
> return 0;
>}
>
>takes your list as input. And outputs:
>
>[...]
>Same color Bs in rqnknbrb
> at line 1670
>Same color Bs in rqnkrbnb
> at line 1673
>Same color Bs in rqnnbkbr
> at line 1676
>Same color Bs in rqnnkbrb
> at line 1679
>1680 lines processed, 960 pos ok
>
>Regards,
>Dieter
Mine was shorter.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
static char string[32767];
int main(void)
{
while (fgets(string, sizeof string, stdin)) {
int i;
int b0 = -1,
b1 = -1;
for (i = 0; i < 8; i++) {
if (string[i] == 'b')
if (b0 == -1)
b0 = i;
else
b1 = i;
}
if ((b0 % 2) != (b1 % 2))
puts(string);
}
return 0;
}
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.