delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/07/23/02:02:17

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Lines: 123
X-Admin: news AT aol DOT com
From: sterten AT aol DOT com (Sterten)
Newsgroups: comp.os.msdos.djgpp
Date: 23 Jul 2004 05:58:11 GMT
References: <20040722210443 DOT 17800 DOT qmail AT web50704 DOT mail DOT yahoo DOT com>
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
Subject: Re: strange error
Message-ID: <20040723015811.04194.00001706@mb-m15.aol.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

below is a version which also crashes when compiled and run
from cmd.exe from WindowsXP. (using GCC 3.2)

gcc qser3.c -O2 -o qser3.exe

then   qser3 -16 1 5 
crashes after all 8 solutions were printed.

This only happens with O2 and O3 and 
only without -g .

In this version the crashing ability seems to be somehow more stable
to small dummy changes inside the program.


---------------------------------------------------


// n even

#include <stdio.h>
#include <stdlib.h>

int s2[999],Sym[99][99],R[99]={0},C[99]={0},Di1[222],Di2[222],Col[99];
int xm,ym,syms,x2,y2,r2,c2,Node[99],sy,u,v,x,y,q,w,n,r,i,solutions=0,c,p=0,o;
// C:column , Di1: diagonals SW-NE , Di2: diagonals NW-SE , Col:columns
// r:actual row , c:actual column

int main(int argc,char*argv[]){

for(i=0;i<99;i++){R[i]=0;C[i]=0;}

    if(argc<2){printf("usage:queen n x y\n\n 180'rotation-symmetric n-quees
solutions with\npreplaced queens on
(x,x),(y,n+1-y),(n+1-x,y),(n+1-y,n+1-x)\n");exit(1);}
    sscanf(argv[1],"%i",&n);if(n<0){n=-n;p=1;}

    for(x=1;x<=n;x++)for(y=1;y<=n;y++)Sym[x][y]=0;
    w=0;for(x=1;x<=n;x++)for(y=1;y<=n;y++){
     u=x;v=y;q=x*n+y;
     r=x*n+n+1-y;if(r<q){q=r;u=x;v=n+1-y;}
     r=(n+1-x)*n+n+1-y;if(r<q){q=r;u=n+1-x;v=n+1-y;}
     r=(n+1-x)*n+y;if(r<q){q=r;u=n+1-x;v=y;}
     r=y*n+x;if(r<q){q=r;u=y;v=x;}
     r=y*n+n+1-x;if(r<q){q=r;u=y;v=n+1-x;}
     r=(n+1-y)*n+n+1-x;if(r<q){q=r;u=n+1-y;v=n+1-x;}
     r=(n+1-y)*n+x;if(r<q){q=r;u=n+1-y;v=x;}
     if(Sym[u][v]==0){w++;Sym[u][v]=w;}
     Sym[x][y]=Sym[u][v];
    }syms=w;

//for(x=1;x<=n;x++){for(y=1;y<=n;y++)printf("%i
",Sym[x][y]);printf("\n");}printf("\n\n");

//goto m21;

    sscanf(argv[2],"%i",&x);x2=n+1-x;
    sscanf(argv[3],"%i",&y);y2=n+1-y;
//xm=x;ym=y;
    C[x]=x;R[x]=2;Col[x]=1;Di1[x+x]=1;Di2[x+x2]=1;
    C[y]=y2;R[y]=2;Col[y2]=1;Di1[y+y2]=1;Di2[y+y]=1;
    C[x2]=y;R[x2]=2;Col[y]=1;Di1[x2+y]=1;Di2[x2+y2]=1;
    C[y2]=x2;R[y2]=2;Col[x2]=1;Di1[y2+x2]=1;Di2[y2+x]=1;

m21:r=0;
m22:r++;if(R[r]  )goto m22;if(r>n)goto m50;
    C[r]=0;
m24:C[r]++;c=C[r];if(c>n)goto m55;
    r2=n+1-r;c2=n+1-c;if(r==c || r==c2)goto m24;
    if(Col[c])goto m24;
    if(Di1[r+c])goto m24;
    if(Di2[r+c2])goto m24;

    if(Col[c2])goto m24;
    if(Di1[r2+c2])goto m24;
    if(Di2[r2+c])goto m24;

    if(Col[r])goto m24;
    if(Di1[c+r2])goto m24;
    if(Di2[r+c])goto m24;

    if(Col[r2])goto m24;
    if(Di1[r+c2])goto m24;
    if(Di2[r2+c2])goto m24;

//printf("");
//for(i=1;i<=r;i++)printf("%i ",C[i]);printf("\n");

m47:Node[r]++;
    R[r]=1;R[r2]=2;R[c]=2;R[c2]=2;
    C[c]=r2;C[c2]=r;C[r2]=c2;C[r]=c;
    Col[c]=1;Col[c2]=1;Col[r]=1;Col[r2]=1;
    Di1[r+c]=1;Di1[r2+c2]=1;Di1[c+r2]=1;Di1[r2+c]=1;
    Di2[r+c2]=1;Di2[r2+c]=1;Di2[c+r]=1;Di2[c2+r2]=1;
    goto m22;
m50:solutions++; 
     for(x=0;x<=syms;x++)s2[x]=0;
     for(x=1;x<=n;x++)s2[Sym[x][C[x]]]=1;
     q=0;for(x=1;x<=syms;x++)q+=s2[x];
//    
if(q==n/2+1){for(x=1;x<=syms;x++)if(s2[x])printf("%c",64+x);printf("\n");}
 if(p){for(i=1;i<=n;i++)printf("%i ",C[i]);printf(" *\n");}
m55:r--;if(R[r]!=1)goto m55;
    c=C[r];r2=n+1-r;c2=n+1-c;
    R[r]=0;R[r2]=0;R[c]=0;R[c2]=0;
    C[c]=0;C[c2]=0;C[r2]=0;//C[r]=0;
    Col[c]=0;Col[c2]=0;Col[r]=0;Col[r2]=0;
    Di1[r+c]=0;Di1[r2+c2]=0;Di1[c+r2]=0;Di1[r2+c]=0;
    Di2[r+c2]=0;Di2[r2+c]=0;Di2[c+r]=0;Di2[c2+r2]=0;
    goto m57;

m57:if(r>0)goto m24;
    printf("%i solutions  \n",solutions);
//   if(o!=20)printf("%i solutions  \n",solutions);  // changing o to p in this
line can changed the crashing behaviour in another version !
//  for(i=1;i<=n;i++)printf("%i ",Node[i]);

//  return 17; // with this command included the program runs correctly
//but the same is true for the xm=x line or 
when you include a new i=3; line or such

}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019