\ fast queens program by Ian Osgood from \ <7ec890f8.0405041426.44374d73@posting.google.com> variable solutions variable nodes : lowBit ( mask -- bit ) dup negate and ; : lowBit- ( mask -- bits ) dup 1- and ; : third ( a b c -- a b c a ) 2 pick ; \ >r over r> swap ; : poss ( a b c -- a b c a&b&c ) dup 2over and and ; : next3 ( dl dr f Qfilebit -- dl dr f dl' dr' f' ) invert >r third r@ and 2* 1+ third r@ and 2/ third r> and ; : try ( dl dr f -- ) dup if 1 nodes +! poss begin ?dup while dup >r lowBit next3 recurse r> lowBit- repeat else 1 solutions +! then drop 2drop ; : queens ( n -- ) 0 solutions ! 0 nodes ! cr 1 over lshift 1- -1 dup rot try . ." queens: " solutions @ . ." solutions, " nodes @ . ." nodes" ;