Jump to content



Photo
- - - - -

The N-queens Problem On A Casio Fx-201p (8 Queens)


  • Please log in to reply
1 reply to this topic

#1 verena

verena

    Casio Fan

  • Members
  • PipPip
  • 41 posts
  • Gender:Female
  • Location:Tashkent

  • Calculators:
    Casio ƒx-10 ~ ƒx-991ES

Posted 10 April 2008 - 12:10 AM

Xerxes:
After several hours of experimenting, here is the n-queens problem solution for the Casio fx-201P:
MAC			   ( zero all memories, including I)
ST# 0: I = I + K1:	   ( I = main index)
	   IM = K9:		  ( range: K5 (4 queens) to K9 (8 queens))
	   IF I = IM: 2: 5:  (note 1) ( if I = Nqueens+1, goto ST# 5)
ST# 1: I = I - K1:	   ( go back if not found for I )
ST# 2: IM = IM - K1:	 ( move one position )
	   9 = K0:		   ( 9 = offset from main index)
	   IF 9 = IM: 3: 1:  ( if IM = 0: off board, go back to ST# 1)
ST# 3: 9 = 9 + K1:	   ( increase offset)
	   IF 9 = I: 4: 0:   ( if offset=I: found, goto ST# 0)
ST# 4: 0 = IM:		   ( remember position )
	   I = I - 9:		( offset the index)
	   0 = 0 - IM x =:   (note 2)(square difference of positions..)
	   I = I + 9:		( reset the index)
	   0 = 9 x 9 - 0 x 0: (..times(squared offset-squared difference))
	   IF 0 = K0: 3: 2: 3: ( if 0 goto ST# 2, if OK goto ST# 3)
The run time for the 127 steps program as presented here (for eight queens) is 53:47 (53 minutes and 47 seconds). So, unfortunately, it just doesn't make it in the top ten of your Calculator Benchmark list, with the three unbeatable Russian MKs in the top three. I could have used the "cos" function instead of "square" (instead of "0 = 0 - IM x =" and "0 = 9 x 9 - 0 x 0", use "0 = 0 - IM" and 0 = 9 cos - 0 cos x 0") to make the difference between the queens' positions positive, and then beat the slow poke HPs and TIs because each "cos" takes about two seconds, but I don't want to cheat, and this is about as fast as it can get.

What saved the day was:
(note 1) Unlike it says in the manual, you don't always have to program "IF M = m : 1 : 2 : 3 :" (meaning: if (memory M)<(memory or constant m) go to label 1; if it is equal, go to label 2; if M > m, go to label 3). When M is always smaller than or equal to m , you can just program "IF M = m : 1 : 2 :" which saves two steps - six alltogether.
Also, the statement with "(note 1)" sends the program to a non-existing label "ST# 5" when done, and the programs stops without error, displaying "0".
(note 2) Unlike it says in the manual, some keystroke programming is allowed, here to calculate the square of something. Just use "x =", in absence of a "square" key (and of course it doesn't have an "Abs" key...).
Good thing, there is no syntax check.

There was no space left for a "node counter", but manual checking after the program has run indicates the following positions for the eight queens, in memories 1 through 8: 8, 4, 1, 3, 6, 2, 7, 5.

Well Xerxes I hope this sufficiently addresses the "n queens" problem you presented in Sergei Frolov's thread "Calculators Speed Comparison". It was fun and I got to know and appreciate my fx-201P quite well, finally. Thank you.

#2 Xerxes

Xerxes

    Casio Freak

  • Members
  • PipPipPipPip
  • 130 posts
  • Gender:Male

Posted 10 April 2008 - 02:51 PM

Hi Verena,

Thank you very much for your effort to make it possible to have one of CASIOs first
programmable calculator from 1976 in the benchmark.

The execution speed is faster than expected considering the necessary adaptions for
fitting in memory and especially in comparison with much later machines.

Yes, I guess it'll be very hard to beat the MK-52 or TI-66, but who knows...

The main reason of the node counter is to have a fast way to check, if the program works
correctly and so it's not really essentiall.

Thanks for the interesting findings of the programming language details. Apparently this
challenge was a good exercise for a better understanding of the unusual Fortran style
keystroke programming method.

I think you have earned 5 stars! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users