> Writing an 8-queens program this morning (teaching my 12-year old son
> about recursion!), I found that "any" led to an easy translation of "can
> I put a queen in any of these columns and get a solution" into concise
> code which did exactly what I wanted.  (see
> http://www.cs.iastate.edu/~slagell/ruby/queens.rb) 

I will post here an independently produced solution (i saw your page
slightly after). The #find and #find_with_index are playing the role of
'any' here.

class Array; def find_with_index
    each_with_index {|x,i| return x if yield(x,i) }
end; end

def queens(a,&f)
  return yield(a) if a.length == 8
  (1..8).each {|u|
    next if a.find {|x| x == u}
    next if a.find_with_index {|x,i| x-i == u-a.length}
    next if a.find_with_index {|x,i| x+i == u+a.length}
    queens(a+u, &f)
  }
end

queens([]) {|a| p a}



PS: note that there are faster/smaller implementations
____________________________________________________
matju