N queens in less than 150 lines

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
Posts: 5
Joined: Mon Feb 22, 2021 3:18 am

N queens in less than 150 lines

Post by arhtur »

I know that the N queens algorithm can be long. Using code I found on the HP museum website by T. Klemm for another calculator, the HP 17BII for 4 queens, I made modifications for 8 queens. My code is a total of 149 lines and runs in about 6.5 seconds (faster than the 7+ time I saw in another post).

First, do XEQ nq8. nq8 will call the nz subroutine. To see the values, recall registers 01 to 08. The integer part holds the row number for each queen.

You should get 1, 5, 8, 6, 3, 7, 2, 4.
(453 Bytes) Downloaded 7 times
(45 Bytes) Downloaded 6 times
Post Reply