From: James Edward Gray II Date: 2006-12-18T01:44:16+09:00 Subject: Fwd: Please Forward: Ruby Quiz Submission Begin forwarded message: > From: darrenks@ml1.net > Date: December 16, 2006 9:51:18 AM CST > To: submission@rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > > Hi, here is my solution to the chess 960 quiz. Since white and > black are the same I decided to just print it once and omit the > whole white/black thing. It is not totally efficient, for position > #960 it will have to iterate about 20,000 times, however it still > runs in about a one second in this case. > > # Chess960 minimalist version > # Author: Darren Smith > # Usage: ruby $0 [1..960] (omit for random position) > > i=$*[0]||rand(960)+1 > srand 1558 > p=%w'K R N B B Q N R' > h={} > while h.size p=p.sort_by{rand} > $_=p*' ' > h[$_]=1if~/R.*K.*R/&&~/B(..)*B/ > end > puts"Position ##{i}:",$_ >