Somewhere between my first and 96th J program 20 or more years ago was a sudoku 
solver "ordered by"  https://projecteuler.net/problem=96

I fell in love with J's ability to "collide nouns together" and express "the 
thoughts I wanted to think into code"

I remember Roger very helpfully commenting on my code, and also remember 
concluding that my code was not very good or the right approach to the problem.

I admire your use/understanding of tacit code, even when it gets embedded in 
large explicit functions.  But, without proper study, it feels too long.  
Though also feels short enough to have obtained the satisfaction of "expressing 
the thoughts you wanted into code"






On Saturday, February 26, 2022, 02:13:16 p.m. EST, 'Viktor Grigorov' via 
Programming <[email protected]> wrote: 





Thank you, Raul, you gave me a few ideas with this. The first was to do the 
properly renew all could-be numbers after each amend. Getting only the the 
indices of the cells with could-be numbers of the face, row, column of a 
particular cell would be a hassle, so it just looks for cells with >1 elements 
and renews all missing numbers. With this almost solves the hard sample. The 
second and more important one, that using a shuffle of the cell indicies in the 
 loop is like attacking from a different angle, giving solutions of varying 
completeness and correctness.

solve=:3 :0
rm=:{{ NB.fixme: renew mn only of a cell's fcr rather than all
for_ijk.{~ ?~@# i.81 do. NB.
if.(0&=)w=.>(<q=.ijk{i){y do.
y=.(is/(<mn(<"1 Q{frc q){y))(<q)}y
elseif.(1:<#)w do.
y=.(is/(<mn(<"1 Q{frc q){y))(<q)}y
end.
end.
y
}}
NB.for_ijk.i.81 do. NB.for_ijk. ((0&=)#(i.@#))EU do.NB.fixme
for_ijk.{~ ?~@# i.81 do. NB.
if.(0&=)w=.>(<q=.ijk{i){y do.
y=.(is/(<mn(<"1 Q{frc q){y))(<q)}y
elseif.(1:<#)w do.
if.(1:=#)e=.(0&~:#])@,@~.@(w((-.@([e."1]))#[)(~.@;@(((<w)~:])#])@((1:<(#@>))#])@:,"2@((<"1
 Q{frc q){])))y do.
y=.(< 1 $ e)(<q)}y
y=.rm y
else.
y=.(is/(<mn(<"1 Q{frc q){y))(<q)}y
end.
end.
end.
y
)

Combining both, (< 9 9 $ , solver hu) , (< 9 9 $ HS) I do get puzzles finally 
correctly solved, but differing because of ambiguous puzzle generation, similar 
to the all windows minesweeper versions before win8 or win10.

The shapes of the all the boxes in my solution vary, hence the discrepancy 
between z and zz when using =, but the numeric overlap can be better seen with

   (<z(="0 &.>)zz), (<z=:9 9 $,solver hu),(<zz)
┌───────────────────┬───────────────────┬───────────────────┐
│┌─┬─┬─┬─┬─┬─┬─┬─┬─┐│┌─┬─┬─┬─┬─┬─┬─┬─┬─┐│┌─┬─┬─┬─┬─┬─┬─┬─┬─┐│
││1│0│0│1│1│0│1│0│1│││3│9│1│2│5│8│6│4│7│││3│1│8│2│5│4│6│9│7││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│0│1│1│0│0│1│0│1│││7│8│6│1│4│3│2│9│5│││7│4│6│1│9│8│2│3│5││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│0│1│1│1│0│1│0│1│││2│4│5│6│7│9│1│3│8│││2│9│5│6│7│3│1│4│8││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│1│1│1│1│1│1│1│1│││4│5│7│3│1│6│9│8│2│││4│5│7│3│1│6│9│8│2││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│1│1│1│1│1│0│1│0│││6│2│9│5│8│7│4│1│3│││6│2│9│5│8│7│3│1│4││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│0│0│1│0│0│1│1│1│││8│1│3│4│9│2│5│7│6│││8│3│1│4│2│9│5│7│6││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│1│1│1│1│1│1│1│1│││1│6│4│8│3│5│7│2│9│││1│6│4│8│3│5│7│2│9││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│0│1│1│1│1│0│1│0│││9│3│2│7│6│1│8│5│4│││9│8│2│7│6│1│4│5│3││
│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│├─┼─┼─┼─┼─┼─┼─┼─┼─┤│
││1│1│0│1│0│0│0│1│1│││5│7│8│9│2│4│3│6│1│││5│7│3│9│4│2│8│6│1││
│└─┴─┴─┴─┴─┴─┴─┴─┴─┘│└─┴─┴─┴─┴─┴─┴─┴─┴─┘│└─┴─┴─┴─┴─┴─┴─┴─┴─┘│
└───────────────────┴───────────────────┴───────────────────┘

Thanks again for the input.



Feb 26, 2022, 17:51 by [email protected]:

> If I remember correctly, Hui built permutations (lists of indices) up
> front that represented the sudoku structures (rows, columns, squares),
> and that because he had found that the claim that there's only one
> solution was not always accurate, he conducted a breadth first search
> (with a different copy of the partially solved sudoku puzzle) for some
> cases.
>
> That said, I took a quick look at your code, and it seems like the
> merge is working (it's updating only a single cell at a time, but it
> is updating...).
>
> FYI,
>
> -- 
> Raul
>

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to