Advertisement
Guest User

sudoku final

a guest
May 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
J 0.63 KB | None | 0 0
  1. NB. Calculate neighbourhoods
  2. u=:~."1 b,.c,.r[r=.9#i.9 9[c=.81$|:i.9 9[b=.(,i{9#i.9){i[i=.(]/. i.@#),{;~3#i.3
  3. NB. Make a guess (based on the cell with the fewest candidates)
  4. g=:3 :'y+"1(1+I.i{b)*/i=i.81[i=.(i.<./) (+/"1 b){10,}.i.10[b=.(0&=>(1+i.9)e."1 u&{)y'
  5. NB. Our solve function (also automatically fills in single candidate boxes without guessing)
  6. s=.(;@:(<@(,:`g@.(0&e.))"1))@:(((27 9$1)-:"2(0&=+.~:"1)@((i,(,|:)i.9 9){"_ 1]))#])@:((+(+/ .*&(1+i.9)*1=+/"1)@(0&=>(1+i.9)e."1 u&{))^:_"1)^:_
  7. NB. Run solve over the input file and exit
  8. exit 0[((stdout&(,&(10{a.)"1)&(s&.('.123456789'&i.)))&.>)"0(#~(a:&~:))<;._1(10{a.),((1!:1)2{ARGV)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement