[Jprogramming] sudoku solver

Hauke Rehr hauke.rehr at uni-jena.de
Wed Oct 13 23:00:35 UTC 2021


Regarding your second question:
I think it should be
is/ a1, a2, a3
Only literal numbers may be joined into an array by juxtaposition.

Am 14.10.21 um 00:52 schrieb 'Viktor Grigorov' via Programming:
> Hello,
> 
> Recently I saw an article in lobste.rs (https://www.hillelwayne.com/post/sudoku/) about sudoku solving, and though t, "it'd be nice to try it J". (Didn't even bother reading it, but later glancing at it found the author had used J in the end. :D)
> 
> I reshape a list of integers of length 81 with blanks being 0s, row-wise, from top, going left-to-right; into a 4-cube of length 3; and define 3 auxiliary verbs.
> 
> g=:3 3 3 3 $ ...
> q=:i.3NB. has missing
> hm=:0&=@(<./)@,
> NB. intersection
> is=:([e.])#[
> NB. missing numbers
> mn=:13 :'((-.((>:@i.9)e.,y))#(>:@i.9))'
> 
> Although one usually solves sudoku (I think) by thinking of exclusions, as the article's first paragraph or so suggested. I wanted to find symmetries or something similar, thinking of it as a higher dimmensional thing, hence the 4-cube. The constraints, or symmtetries, or whatever they may be are the 9 rows, columns, and faces each containing 1--9 once. My idea is to try each of the 81 cells until once with only one overlap is found, break, then repeat until no change.
> 
> The sudoku given as an example in the english wikipedia article for sudoku has an 'easy' example, wherein the center of the center resolves to 5 using the intersection of the missing numbers of the 5. row, 5. column, and 5. face; or within the tesseract:
> 
> (mn(<1;q;1;q){g)is(mn(<1;1;q;q){g)is(mn(<q;q;1;1){g)
> ((mn(<1;q;1;q)&{)is(...)is(...))g NB. nope
> 
> Taking out g and binding the from doesn't work, giving me just 1--9. Trying  to take out the coordinates doesn't fair well for me either.
> 
> How can one shorten the former expression using bindings?
> 
> My second question regards is/: if I define a1, a2, a3 as missing numbers in the row, column, face of some cell, why does is/ a1  a2 a3 give a syntax error, when a1 is a2 is a3 doesn't?
> 
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 

-- 
----------------------
mail written using NEO
neo-layout.org



More information about the Programming mailing list