FWIW, I've been looking at this, and my own slower and more
space-consuming versions.
I tried amending Roger's similar original code, posted in the forum, I
think, with obvious
changes as follows. Some of his verbs, including your ac & ar I think
differ in the wiki article
from the ones I have. I've used suffixes x or hx for hex:
NB. Hui's solution for 16x16?
size2x =: 2#sizex =: *: smallx =: 4
jx =. (]/. i.@#) ,{;~smallx#i.smallx
rx =. size2x $"1 i.size2x
cx =. (size2x$i.sizex){|:i.size2x
bx =. (jx{sizex#i.sizex) { jx
Ix =: rx,"1 cx ,"1 bx
Rx =: jx,(,|:)i.size2x
freex =: 0&= > (1+i.sizex)"_ e."1 Ix"_ { ,
regionsx=: Rx"_ {"_ 1 ,"2
eux =: e.&(i.sizex+1) *. 0&= +. ~:"1
okx =: (1$~(smallx,1)*size2x)"_ -:"2 eux@regionsx
s1ux =: 3 : 0
m=. 1=+/"2 Rx{,/y
j=. I. +./"1 m
k=. 1 i."1~ j{m
i=. ,(k{"_1 |:"2 (j{Rx){,/y) #"1 j{Rx
size2x$(1+k) i}0$~*/size2x
)
NB. s1x =: +/ .*&(1+i.9) * 1: = +/"1
NB. s1 =: (+ (s1x >. s1u)@free)^:_"2
NB. sudoku =: s2 @: (ok # ]) @: s1 ^:_
s1xx =: +/ .*&(1+i.sizex) * 1: = +/"1
s1hx =: (+ (s1xx >. s1ux)@freex)^:_"2
s2ax =: 3 : 0
if. -. 0 e. ,y do. ,:y return. end.
b=. freex y
i=. (i.<./),(+/"1 b){(1+sizex),}.i.sizex
d=. 1+I.i{,/b
y +"2 d *"0 2 i=i.size2x
)
s2x =: ; @: (<@s2ax"2)
sudokux =: s2x @: (okx # ]) @: s1hx ^:_
NB. ==================================================================
When I run this on my solvable array, sixteen2, it fails:
s1x sixteen2
|length error: s1x
| s1x sixteen2
Debug shows the error occurs in or around freex, but I haven't yet
discovered how.
Here's sixteen2:
sixteen2
3 6 0 0 0 0 4 15 12 11 13 2 8 0 5 0
0 0 15 0 1 0 14 0 0 0 8 0 13 0 0 0
0 14 13 0 0 8 10 0 0 16 5 0 0 0 0 0
0 5 4 0 0 0 0 0 0 0 0 7 3 11 0 2
0 0 9 0 0 7 0 0 0 0 3 10 6 4 0 0
0 11 0 0 4 13 0 0 0 0 0 0 7 15 10 8
0 0 0 0 15 0 0 0 0 0 6 4 11 0 14 0
0 15 0 0 0 0 6 0 13 2 0 0 9 12 0 0
12 1 0 0 0 3 0 6 9 4 14 8 5 0 0 0
0 0 0 0 13 2 0 12 0 5 10 3 1 14 9 0
2 0 0 9 0 5 0 0 11 12 7 0 0 8 15 0
0 0 8 14 0 4 7 11 1 13 0 0 0 0 0 0
4 0 0 0 3 0 16 0 0 6 0 0 0 0 0 0
16 7 12 13 14 9 0 2 8 0 0 0 0 10 0 0
11 0 1 0 0 15 0 0 0 0 0 0 0 5 0 0
15 8 0 0 6 0 5 10 3 0 0 0 0 7 11 0
My own code is more secure in APL, and too long-winded
to share here!
Cheers,
Mike
On 19/06/2022 17:42, Brian Schott wrote:
Raul,
I truly appreciate your comments and while they seem very reasonable I do
not know how to delve more deeply into the permutations as you suggest. I
am leaning more to dropping the idea of finding a solution based on Roger’s
algorithm. Instead I want to look more closely at his results for the verbs
AR and AC. In his algorithm he takes the larger of the two results, that is
the larger of AR or AC , where he expects one of each pair to be zero and
the other to be a valid candidate. Whenever there is a nonzero AC it is a
unique and correct candidate, but the values for AR are selected using
index of, i. . I am suspicious that the selection of AR is almost arbitrary
and is causing the problem. I think a human being could do a better job of
selecting among the alternatives from AR.
By the way in my definition for the verb AR the final negative one should
be a zero, but it doesn’t change things much. Also in my text above I am
capitalizing AR and AC but they are lowercase verbs.
If I am correct about using AR and AC to help a human, I would use a
variation on AC that shows all of the possible results instead of the one
captured by the ‘index of’ primitive. In light of that I am looking for
ways to use 4 x 4 arrangements of dots to display each of the cell’s
information. I was looking in the Unicode lists for 4 x 4 dot arrangements
but was unable to find any, so I am trying to imagine alternatives. So far
I can only think of using viewmat to construct the dot patterns.
Any more ideas?
--
(B=) <-----my sig
Brian Schott
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm