Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
I also got 5040 for the arrangement of the back row, but it was via the following formula.
8! / 8, which is 7! or 5040.
If there were 8 distinct pieces, you could arrange them in 8! ways. For each pair of identical pieces (rooks, knights, bishops), you have over estimated by a factor of two. Hence divide by eight (divide by two three times).
I do not understand how Kedaman arrived at his formula, which gives the same numeric result.
W. W. Rouse Ball wrote a book (Mathematical Recreations & Essays) which claims that you can place 8 Queens on a chess board in such a way that no captures are possible.
I trust that book, and assume that the queens are arranged by scrambling an 8X8 Identity matrix. I think such a matrix is called a permutation matrix because when used as a multiplier, it merely exchanges (Id est permutes) rows/columns of the multiplicand matrix. No two Queens are in the same row, no two are in the same column, and you have to avoid diagonal captures.
I suspect that knight moves provide the clue to placing the queens. Perhaps put the first one in a corner, and place the others by making knight moves. This should be a good start at a solution.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
After many tries i thought it was just impossible, well I have to look again.
2 rooks can be placed in 28 different ways on 8 columns, that you usually do with
8!
_____
2!(8-2)!
or
(8)
(2)
or
8 nCr 2 (easier to type)
I did use Pascal's triangle instead, since my calculator couldn't be found.
After placing the rooks, there's 6 columns for 2 bishops, hence 6 nCr 2 which is 15, and 4 columns for 2 knigts which is 6, 2 columns for the queen and one for the king. The product is 5040
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
int main()
{
char a[8];//available row
char p[8];//queen position
char du; //upper diagonal counter
char dl; //lower diagonal counter
for(char* ia=a;ia<&a[8];++ia)*ia=1;//all queens in first row
for(char* ip=p;ip<&p[8];++ip)*ip=0;
for(ia=a,ip=p;ia<&a[8]; ){//for each column
for(;*ip<8;++*ip){//put queen in next row
if (a[*ip]){//row availability
du=*ip;dl=*ip;//reset diagonal counters
for(char* ca=ip-1;ca>=p;--ca){ //diagonal availability
++du;--dl;
if ((*ca==du)|(*ca==dl))
break;
}
if (ca<p)//no diagonal attackers
break;//place next queen
}
}
if (*ip==8){//queen attacked in all rows
--ip;//backtrack
a[*ip]=1;//make available
++*ip;
//cout << "B";
}
else{
a[*ip]=0;//make unavailable
++ip;//move to next column, reset queen
*ip=0;
//cout << "N";
}
for(char* cp=p;cp<&p[8];++cp)cout << (int)*cp;
cout << " :: ";
for(char* ia=a;ia<&a[8];++ia)cout << (int)*ia;
cout << endl;
for(int c=0;c<10000000;c++);
}
for(ip=p;ip<&p[8];++ip)cout << (int)*ip;
return 0;
}
This program i made in c++ works in a way, but it fails to notice when it finds the correct combination, and instead starts to go terribly wrong with two queens at the same row and then locks on a single combination which i first thought was the correct one. Anyways 00000000 should mark the correct combination, with the queens at the correct rows.
Last edited by kedaman; Aug 27th, 2001 at 05:49 AM.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Originally posted by Guv
W. W. Rouse Ball wrote a book (Mathematical Recreations & Essays) which claims that you can place 8 Queens on a chess board in such a way that no captures are possible.
Ok maybe i am too tired to get this I can see how 7 would easily work but not how 8 is possible. can u or someone else pls post a pic of chessboard with 8 on it.
Regards
Stuart
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
the effect of permutation starts to show at a board of size 29 which takes about 3 secs, 30 took 4 minutes (112,852,992 iterations in the outhermost loop). Of course that would take centillion milleniums if my algoritm hadn't strong recursion terminators
of course i could try 31 but it surely takes some hours
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Well the answer I was looking for was that you can put 64 queens of the same colour on the board (!).
But it looks like you guys have some neat code. Cool, I like.
Guv and keda:
8! / 8 = 2nCr8 * 2nCr6 * 2nCr4 * 2 = 5040
this is because the Cr just hides the factorial. If you check what the formula for Cr is then all is clear.
Cool. Tomorrow I will ask for help with an algorithm that has been bugging me for aaages...
There are 10 types of people in the world - those that understand binary, and those that don't.
The 2nd question is a variation of the 8 queens problem (how can you place 8 queens on a sanderd chess board without any being able to attack another, assuming that all are enemies).