Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A slightly longer version using a matcher and no inner closure (213 209 characters plus 2 newlines):

Code Block
def r(a){def m=a=~'0';if(m.find()){int i=m.start();(('1'..'9')-(0..80).collect{
j->int q=j/9,r=i/9,u=jq/273,v=ir/273,w=j%9/3,x=i%9/3;q==r||j%9==i%9||u==v&&w==x?
a[j]:'0'}).each{r(a[0..<i]+it+a[i+1..-1])}}else printlnprint a}

Or without the matcher (193 characters plus two newlines):

Code Block

def r(a){int i=a.indexOf(48);if(i<0)print a else(('1'..'9')-(0..80).collect{j->
int q=j/9,r=i/9,u=q/3,v=r/3,w=j%9/3,x=i%9/3;q==r||i%9==j%9||u==v&&w==x?a[j]:'0'
}).each{r(a[0..<i]+it+a[i+1..-1])}}

Also see another version for a more understandable (though much longer) algorithm - but it also does a lot more.