SUDOKU for the 49g+  (SD card not required)
-------------------

Copy the SUDHP directory to your 49g+.
It contains
ALPHA - for new puzzle input.
SUD - for solving.
Those are all one uses, normally.

Also it contains A2S and S2A for converting between
array/string representations, a sample puzzle called V14, and
the hpgcc binary SUDhpgcc. Thanks to reth on comp.sys.hp48 (13
Aug 2005) these now ensure we have integer output, even when
approximate mode is set.

Test drive by recalling V14 and running SUD.
V14 is a *string* version of the Nihilist's "diabolical" puzzle.
When you see the solution, press ON, and the *string* version of
the solution will be on the stack.
A variable called STRIO will be created - with value 1
signifying that the stringed representation was last used.

Now if you run ALPHA you are presented with a 9 by 9 *string* to
edit, after which you can re-run SUD, to solve your new
puzzle.

Now, recall V14 and press S2A to see the 9 by 9 *array*
representation. 

S2A alows up to 8 extraneous objects of any type to be stored
after the 81 numbers. They are ignored on converting to the
array - in fact V14 has a "string" (well, technically 3
algebraic objects) after the numbers.

SUD will also solve this, and return an *array*.
Now if you run APLHA you will have a zero 9 by 9 *array* for
editing, to create you next puzzle.

So, we can work in whichever mode we prefer - SUD decides :-)

Genesis:
-----------------
Date: Mon, 25 Jul 2005 10:49:35 +1000
From: Al Borowski <al.borowski@EraseThis.gmail.com>
Newsgroups: comp.sys.hp48
Subject: Re: hpgcc is for games

Hi,

> A generalised sudoku solver defintely needs speed and at
>
> http://www.users.waitrose.com/~nihilist/sudoku.html
>
> there is C source for an excellent solver... and this
> compiles on the 16 bit 200LX using PowerC (by MIX)... and
> runs - even the most diabolical example (16 levels of
> recursion) takes only 10 minutes.

Maybe you could try the file at
http://alpage.ath.cx/sudoku.zip ?

Currently it takes a raw text file, SUDOKU.TXT from the SD
card. Copy sudoku.txt to the SD card, and run SUD to see the
solution. The program runs at 12MHz to save batteries but I
can speed it up if its too slow.

By the way, ten minutes is how long it took to port it to the
HP :-)

Al
--------------
In text:

ALPHA:
\<< { 9 9 } 0 CON STRIO TYPE 6 ==
  \<< 1 'STRIO' STO
  \>> IFT STRIO 1 == :: A2S IFT FONT6 \->FONT EDITB
\>>

This was SUD
SUD:
\<< DUP TYPE 2 == DUP 'STRIO' STO :: S2A IFT 
    OBJ\-> DROP SUDhpgcc { 9 9 } \->ARRY 
    STRIO :: A2S IFT
\>>

Now it ensures ZINTs as input to SUDhpgcc even if ALPHA 
or S2A is not used:i.e a real array is directly fed to SUD.

SUD:
\<< DUP TYPE 2 == DUP 'STRIO' STO :: S2A IFT 
    OBJ\-> OBJ\-> DROP * \->LIST R\->I
    OBJ\-> DROP SUDhpgcc { 9 9 } \->ARRY 
    STRIO :: A2S IFT
\>>

alternatively use A2S S2A to turn a real array into an integer
array instead of  OBJ\-> OBJ\-> DROP * \->LIST R\->I :-)

A2S: (R->I and extra TAIL from reth)
\<< AXL OBJ\-> \-> d
  \<< 1 d
    START R\->I \->STR TAIL TAIL DUP "}" POS 10 CHR REPL d ROLLD
    NEXT 1 d 1 -
    START +
    NEXT
  \>>
\>>

S2A: (Now ensures integer array elemnts).
\<< DUPDUP 10 CHR POS 1 SWAP SUB DEPTH 1 - \-> d
  \<< OBJ\-> DEPTH d - \-> w
    \<< w DROPN OBJ\-> DEPTH d - 1 + DUP w / IP w * DUP \-> h
       \<< - DROPN h \->LIST R\->I OBJ\-> 
             w / w 2 \->LIST \->ARRY
        \>>
      \>>
    \>>
  \>>
\>>

V14:
"0 0 0 0 4 0 0 3 0
9 8 0 6 0 1 0 0 0
0 0 0 0 0 0 2 0 0
0 0 0 0 0 0 0 0 1
0 0 4 0 5 0 7 0 0
6 0 0 0 0 0 0 0 0 
0 0 5 0 0 0 0 0 0
0 0 0 9 0 8 0 7 6
0 7 0 0 3 0 0 0 0
The Diabolical One.
"
T Hutchins
14 August 2005.
P.S. SUDhpgcc.C should also now be included :-)
