i know that there are many other solutions to this problem but i choosed to go with the code posted bellow ; however i encountered some problems
the last displayed solution(generated with #1 method) should be (15C6 in this case) 10 11 12 13 14 15 right ? but i get 10 11 12 13 14 16 ..i tried many changes (including cout instead of printf,changing the compiler - tried borland c++ for dos,borland c++ builder 4,borland c++builder 5,microsoft visual c 6)..same result . Can you please tell me ..where i'm wrong ?
the source :
#include <stdio.h>
#include <conio.h>
#include <vcl.h> // delete this line (i wrote the source in borland c++ builder)
short nonrep(short x[6])
{
short w,z,a;
a=0;
for(z=1;z<=6;z++)
for(w=1;w<=6;w++)
if((w!=z) && (x[w]==x[z])) a=1;
if (a==0) return 0;
else return a;
}
void main()
{
short b[6],y[6];
short i,j,k,l,m,n,v;
short nop[3][100];
unsigned long no=0;
for(y[1]=1;y[1]<=10;y[1]++)
for(y[2]=2;y[2]<=11;y[2]++)
for(y[3]=3;y[3]<=12;y[3]++) // #1 method
for(y[4]=4;y[4]<=13;y[4]++)
for(y[5]=5;y[5]<=14;y[5]++)
for(y[6]=6;y[6]<=15;y[6]++)
if ((y[1]<y[2])&&(y[2]<y[3])&&(y[3]<y[4])&&(y[4]<y[5])&&(y[5]<y[6]))
/*
for(y[1]=6;y[1]<=15;y[1]++)
for(y[2]=5;y[2]<=14;y[2]++)
for(y[3]=4;y[3]<=13;y[3]++) // #2 method
for(y[4]=3;y[4]<=12;y[4]++)
for(y[5]=2;y[5]<=11;y[5]++)
for(y[6]=1;y[6]<=10;y[6]++)
*/
{
for(i=1;i<=6;i++) b=y;
if (nonrep(b)==0)
no++;
// {printf ("\n no:%u generated solution: ",no);
// for(v=1;v<=6;v++) // to print each solution
// printf(" %d",b[v]);
// }
}
{ printf ("\n no:%u generated solutions : ",no);
for(v=1;v<=6;v++) // to print last solution
printf(" %d",b[v]);
}
getch();
}
EDIT : has someone tried the program ?what does it prints as the last solution ?
the last displayed solution(generated with #1 method) should be (15C6 in this case) 10 11 12 13 14 15 right ? but i get 10 11 12 13 14 16 ..i tried many changes (including cout instead of printf,changing the compiler - tried borland c++ for dos,borland c++ builder 4,borland c++builder 5,microsoft visual c 6)..same result . Can you please tell me ..where i'm wrong ?
the source :
#include <stdio.h>
#include <conio.h>
#include <vcl.h> // delete this line (i wrote the source in borland c++ builder)
short nonrep(short x[6])
{
short w,z,a;
a=0;
for(z=1;z<=6;z++)
for(w=1;w<=6;w++)
if((w!=z) && (x[w]==x[z])) a=1;
if (a==0) return 0;
else return a;
}
void main()
{
short b[6],y[6];
short i,j,k,l,m,n,v;
short nop[3][100];
unsigned long no=0;
for(y[1]=1;y[1]<=10;y[1]++)
for(y[2]=2;y[2]<=11;y[2]++)
for(y[3]=3;y[3]<=12;y[3]++) // #1 method
for(y[4]=4;y[4]<=13;y[4]++)
for(y[5]=5;y[5]<=14;y[5]++)
for(y[6]=6;y[6]<=15;y[6]++)
if ((y[1]<y[2])&&(y[2]<y[3])&&(y[3]<y[4])&&(y[4]<y[5])&&(y[5]<y[6]))
/*
for(y[1]=6;y[1]<=15;y[1]++)
for(y[2]=5;y[2]<=14;y[2]++)
for(y[3]=4;y[3]<=13;y[3]++) // #2 method
for(y[4]=3;y[4]<=12;y[4]++)
for(y[5]=2;y[5]<=11;y[5]++)
for(y[6]=1;y[6]<=10;y[6]++)
*/
{
for(i=1;i<=6;i++) b=y;
if (nonrep(b)==0)
no++;
// {printf ("\n no:%u generated solution: ",no);
// for(v=1;v<=6;v++) // to print each solution
// printf(" %d",b[v]);
// }
}
{ printf ("\n no:%u generated solutions : ",no);
for(v=1;v<=6;v++) // to print last solution
printf(" %d",b[v]);
}
getch();
}
EDIT : has someone tried the program ?what does it prints as the last solution ?