From: Joey Date: 2006-07-16T08:38:33+09:00 Subject: Re: Who likes Sudoku? ------=_Part_51490_1092897.1153006710317 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Cut down, and formatted: def s;h={};81.times{|j|next if$p[j]>0;80.times{|k|h[ $p[k]]=1 if k/9==j/9||k%9==j%9||k/27==j/27&&k%9/3==j% 9/3};1.upto(9){|v|($p[j]=v;s)if !h[v]};return$p[j]=0} p "Solution:#$p"end;$p=$*[0].split(//).map{|v|v.to_i};s :) j`ey http://www.eachmapinject.com On 7/15/06, Adam Shelly wrote: > > On 7/15/06, Adam Shelly wrote: > > Yes, before we golf this further, does it even work? > > oops, my mistake. I was giving it a filename containing a puzzle on > the command line instead of the puzzle itself. It does run and > converge - but it leaves the last digit 0 unless you make the outer > loop 81.times. Here's what I've got - I mapped the input to > integers, which removed a bunch of 'to_i's. > def s; h={} > 81.times{|j| next if $p[j]>0 > 80.times {|k| h[$p[k]] = 1 if k/9==j/9 || k%9==j%9 || k/27==j/27 > && k%9/3==j%9/3} > 1.upto(9){|v| $p[j]=v and s unless h[v]} > return $p[j]=0; } > p "Solution: #{$p}" > end; > $p = $*[0].split('').map{|v|v.to_i}; s > > ------=_Part_51490_1092897.1153006710317--