Post Reply 
N-Queens on 50g (RPL language)
11-01-2014, 10:03 AM
Post: #2
RE: N-Queens on 50g (RPL language)
Here's my entry, still using the same algorithm:
[49G] 125 bytes #A38Ch

Code:
\<<
  0.
  DO
    8. SWAP 1. +              @ Add Queen
    WHILE
                              @ Test if Qn can be caught by Q1..Qn-1
      DUP2                    @ Q1 .. Qn n Qn n
      DO 1. -                 @ Q1 .. Qn n Qn n-i
      UNTIL
        DUP2 5. + PICK - ABS  @ n-i |Qn-Qi|
        DUP2 - * NOT          @ n-i T/F
      END
    REPEAT                    @ Qn can be caught
      DROP
                              @ Next square for Queen
      WHILE SWAP DUP 1. SAME
      REPEAT -                @ Drop Queen - will not remove the first
      END
      1. - SWAP
    END
    DROP
  UNTIL DUP 8. SAME           @ Done
  END
  \->LIST
\>>

Compatible with all RPL models, I think.
timing on a real 49G: 54_s

Cheers, Werner
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: N-Queens on 50g (RPL language) - Werner - 11-01-2014 10:03 AM
RE: N-Queens on 50g (RPL language) - Han - 11-06-2014, 03:29 AM
RE: N-Queens on 50g (RPL language) - Bruno - 09-08-2015, 10:41 AM
RE: N-Queens on 50g (RPL language) - Han - 11-20-2014, 08:53 AM



User(s) browsing this thread: 1 Guest(s)