Sorry for late posting - apparently a problem with my broadband
provider's server.
Yes, it can be worth doing a limited feasibility check on your input.
Every column,
row and small box should have no repeated elements apart from the "missing"
indicator, such as 0 or perhaps one of '.-*0' , eg, using my
generalisation of Roger's code:
*/ (2 */ @: > #/.~@: -.&0)"1 R{,fiend NB. fiend is a numeric 9x9
puzzle
1
It might be of minor interest to note I've got my modification of Roger
Hui's wiki essay
code to solve a 25x25 puzzle which I lifted from an online source,
https://www.sudoku-puzzles-online.com/
Annoyingly, I haven't dicovered how to download it in a form usable
directly by J. I
spent far too much time transcribing just one 25x25 puzzle by eye and hand.
I modified the solve function , posted on 20 June. just a tad to allow
the input of a character
representation. I'll just reproduce the new and amended lines:
solve =: 3 : 0
'.123456789abcdefghjklmnpqrstuvwxyzA' solve y NB. x is a default
representation for up to 36x36 just:
if. ' ' = 1{.0{.ry =. , y do.
chars =. ''
chars =. chars, /:~ ~., ' .*-' (e.~#]) ry NB. any other
representations of unknown cells?
chars =. chars, /:~ ~., '123456789' (+./@:e.~#[) ry
chars =. chars, /:~ ~., 'abcdefghijklmnopqrstuvwxyz' (+./@:e.~#[) ry
chars =. chars, /:~ ~., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' (+./@:e.~#[) ry
sudokurep =: chars
y =. chars i. y
else.
sudokurep =: x
end.
.....
see1 =: (;~n2$n1{.1)&(<;.1) @ ({&sudokurep) @ (n22&$) @ ,
.....
)
Here's the puzzle I copied, "confirmed" or "advanced" number 7957:
t25 =: (#{."1 ] ) dtb"1 >LF cut 0 : 0
j g n os wc iy r aup
o qf w n mgeb
ycaix rlp t b d nvs
n qcb e vg x t
wbmks ig pnf cd
p s w fxa d v u l
k u xyv rhog cj p q
tj e nq sy xo mbf w
lxob ufk i t d ns
rqdtc w uh o g
u kt o i vbpm gj h
j xv pdrqwat o u
atib sym h w jod nfcx
o w dfbtkns ux a
v he ligq b c fk d
g x ud m yebqt
lh r p s dmw gcxu
q rmn pk tw fg b sh
m b ac hoej urx p y
t o s d bga h f i
cn yps db vukfe
x p vh b kwa j
ajy n f p hte sdriw
bfud n v im x
wli j ur xv pf q b n
)
see {:solveh t25
┌─────┬─────┬─────┬─────┬─────┐
│jxegv│nktos│bwcdi│ymqhr│laupf│
│toprq│fdjvw│syuxn│icakl│hmgeb│
│hycai│xmrlp│ogtkf│bedju│nvsqw│
│ndflu│aqcby│ejmph│swvgo│ixrkt│
│wbmks│uheig│qlvar│txpnf│yjcdo│
├─────┼─────┼─────┼─────┼─────┤
│ipysh│rgowm│fxaed│qnkvj│utlbc│
│knwue│ibxyv│lrhog│asftc│jdpmq│
│gavtj│delnq│cusyp│xoimb│fkwhr│
│clxob│hufkj│ivqmt│gprdw│aeyns│
│fmrqd│tcpsa│wbknj│luhey│xovgi│
├─────┼─────┼─────┼─────┼─────┤
│usdcl│ktwao│xiyfe│nvbpm│qgjrh│
│ykjfn│exvhc│mpdrq│watig│olbsu│
│atibp│symur│ghlwv│eqjod│knfcx│
│oqgmw│pjdfb│tknsc│rluxh│eiayv│
│vrhex│ligqn│jaobu│cysfk│pwmtd│
├─────┼─────┼─────┼─────┼─────┤
│pgsxc│waudh│vfrlm│oinye│bqtjk│
│lhkyf│orbte│pniqs│jdmwv│gcxua│
│djqvr│mnipk│ytwux│fgcba│sheol│
│mibna│cfqgl│hoejk│urxst│wpdvy│
│eutwo│vsyjx│dcbga│khlqp│rfnim│
├─────┼─────┼─────┼─────┼─────┤
│rcnhg│ypsmi│aqjtw│dbolx│vukfe│
│xeopt│gvhrd│usfib│mkwan│cyqlj│
│qvajy│blnxf│kmpco│hteus│driwg│
│bfudk│qwact│neghl│vjyri│msoxp│
│swlim│jokeu│rdxvy│pfgcq│tbhan│
└─────┴─────┴─────┴─────┴─────┘
ts
6!:2 , 7!:2@]
ts'solveh t25' NB. performance ok for this example
0.0374274 1461408
They offer even larger puzzles, but I'll avoid those until I see how to
download them
in a usable format!
On 20/06/2022 18:00, Brian Schott wrote:
All,
My code is not perfect, but the error I was noticing in trying to step
through the algorithm using the verbs f and diff were correct, BUT my
initial data in the noun raw was missing a starting SPACE. So the example
data was unsolvable. When I corrected the data, I was able to get an answer
with Mike's most recent verb 'solve', and it looks like it is the correct
answer.
I apologize for the noise. And will try to improve my solution now; for
some reason my version of 'sudoku' is flawed, but I think I can rectify
that now that I have a working version of the verbs f and diff.
Again, I apologize. And thank you.
----------------------------------------------------------------------
For information about J forums seehttp://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