M=*0..id%9 def f*r puts r*" "if[]==(M-r).map{|a|z=0;f *r+[a]if r.map{(a-r[-z+=1]).abs!=z}.all?}end f