in reply to Efficient N-Queen solution with Perl

<geezer> Ahh this takes me back. Back around '84 a FORTRAN instructor assigned an 8x8 Queens problem to the class as an extra credit assignment. Elegance wasn't a requirement.

Since I was more interested in writing games, simulations, and comm software than solving logic problems it didn't hold any interest for me. But after a couple of weeks it was apparent that no-one else was making any headway on solving the problem. The instructor gloated.

One afternoon I hacked up a pure Brute Force and Ignorance solution. Howzat? All of the arrangements of 8 queens on a chessboard can be represented as a base-8 counter. Initialize it to 00000000 and add one. Check to see if any digits are repeated or any digits are rows+cols offset from each other (diagonal). Lather, rinse, repeat. It took all of an hour to write and debug, most of that fighting the line editor.

Unleashing that on our Prime 950 (I think it was running PrimeOS 7?) it immediately ground the entire machine to a slow death. Fearing being tortured by my classmates and having the lab people hunt me down like an animal, I managed to stop the program and sneak out. Before I did, I set the program to run at midnight (a phantom job) that night and dump results (the octal numbers representing successful matches) to a file.

The next morning I got the results. 96 matches (which was correct) including rotations and mirrors. The job ran for 1 hour and 10 minutes, and used 1 hour and 3 minutes of CPU time. Thank God this particular University didn't charge students for CPU time.

I used Pascal (which I liked better at the time) to take the results and format them according to the instructor's wishes. I had actually used FORTRAN to solve the problem, so I wasn't cheating... </geezer>

  • Comment on Re: Efficient N-Queen solution with Perl