Sudoku Solver for HP-33s



#2

This is impractically slow on the HP-33s and not really useful, but it does work. It is a brute force solver for Sudoku puzzles. It will find the first solution to any solvable puzzle.

This was written for the HP 15c and is not really designed to make full use of the 33s. It could probably be a *lot* faster on the 33s with a bit of work, but my real focus was to validate the 15c code and so I have not put an effort into optimizing it on the 33s.

To run: XEQ A

It will prompt you to enter values Q through Y which represent row 1 through 9 of the unsolved sudoku puzzle.

In your input, the digit 0 represents an unsolved space. For example 100070003. You do not have to enter leading 0s.

When the program finishes (many many hours later, if you have given it a simple puzzle), You will find the solved rows in Q through Y. (There should really be a loop that spits them out).

Have fun and sorry for the lack of documentation. I will post that separately. HP 15c version is on the way.

Marcel

-----------------


/************************************************************************
getPart()
************************************************************************/
LBL F (CN=B583)
ENTER
ENTER
8
XEQ H
RCL (i)
RTN

/************************************************************************
setPart()
************************************************************************/
LBL G (CN=2942)
ENTER
8
XEQ H
STO (i)
R DOWN
RTN

LBL H (CN=F793)
+
STO i
R DOWN
RTN

/***********************************************************************
setPow2()
***********************************************************************/
LBL J (CN=8F3C)
STO Z
1
-
2
XY SWITCH
POW
X EXCH Z
RTN

/***********************************************************************
setU()
***********************************************************************/
LBL O (CN=D238)
XEQ J
RCL B
XEQ N
RCL C
XEQ N
RCL D
XEQ N
RTN

// imp subroutine that does setPart(x, getPart(x) + reg[VAR_TMP1])
LBL N (CK=ADAF)
XEQ F
RCL Z
FS? 3
CHS
+
XY SWITCH
XEQ G
XEQ M
RTN

/***********************************************************************
putA()
***********************************************************************/
LBL L (CK=7A6C)
X <> F
STO Z
RCL B
17
XEQ H
RCL (i)
RCL F
RCL Z
-
RCL E
*
+
STO (i)
RTN

/***********************************************************************
change()
***********************************************************************/
LBL K (CK=C833)
STO+ A
RCL A
9
INT /
STO B
RCL A
9
RMDR
STO C
3
INT /
RCL B
3
INT /
3
*
+
STO D
8
RCL C
-
10^X
STO E
RCL B
17
XEQ H
RCL (i)
XEQ I
STO F
STO G
R DOWN
RCL C
28
+
XEQ J
RCL B
XEQ F
RCL Z
INT /
2
RMDR
X<=0?
STO G
RTN

LBL I (CK=9AD5)
RCL E
INT /
10
RMDR
RTN

/***********************************************************************
main()
***********************************************************************/
LBL A (CK=0970)
CLRVARS
INPUT Q
INPUT R
INPUT S
INPUT T
INPUT U
INPUT V
INPUT W
INPUT X
INPUT Y
1
CHS
STO A

LBL D (CK=D600)
1
XEQ K
RCL F
X<=0?
GTO Q
XEQ O
RCL C
28
+
XEQ J
RCL B
XEQ F
RCL+ Z
XY SWITCH
XEQ G

LBL Q (CK=FEB7)
80
RCL A
X NE Y?
GTO D
1
CHS
STO A

LBL E (CK=E698)
1
XEQ K
9
RCL B
X=Y?
R/S // finished!!!!!
RCL G
x>0?
GTO E
XEQ L

LBL X (CK=0B63)
9
RCL F
X=Y?
GTO C
1
+
XEQ L
RCL F
XEQ J
CF 2
RCL B
XEQ P
FS? 2
GTO X
RCL C
XEQ P
F? 2
GTO X
RCL D
XEQ P
F? 2
GTO X
RCL F
XEQ O
GTO E

LBL C (CK=E045)
1
CHS
XEQ K
X>0?
GTO C
RCL F
SF 3
XEQ O
CF 3
GTO X

LBL P (CK=014A)
XEQ F
RCL Z
INT /
2
RMDR
X>0?
SF 2
R DOWN
R DOWN
XEQ M
RET

LBL M (CK=204F)
9
+
XEQ J
RTN


#3

You should post this to the "Articles" forum so that it is easier to access in the future.

#4

Congratulations of this marvel. As I am such an advocate of the programmable calculator (especially HPs and RPN), this is a strong testament to the relevance, importance and significance of them. Even in this era of the iPad, MS Excel and Android, the programmable calculator is and will always be essential, vital and significant.

Edited: 10 May 2012, 3:25 p.m.


#5

MS Excel? :/

Why not Matlab?


Possibly Related Threads...
Thread Author Replies Views Last Post
  hp-prime solver and variable name fabrice48 22 1,741 12-10-2013, 03:25 AM
Last Post: fabrice48
  Solver issue with HP 17BII - different from 19BII Jeff Kearns 13 846 11-28-2013, 02:36 AM
Last Post: Don Shepherd
  HP Prime Triangle solver BruceH 29 1,809 11-28-2013, 12:03 AM
Last Post: Dale Reed
  HP prime: linear solver app Alberto Candel 1 318 11-21-2013, 01:57 AM
Last Post: Michael Carey
  HP Prime: Linear Solver app bug BruceH 0 209 11-15-2013, 06:36 PM
Last Post: BruceH
  HP Prime Solver Variables Issue Anibal Morones Ruelas 8 693 10-19-2013, 09:45 AM
Last Post: Harold A Climer
  HP Prime triangle solver oddity BruceH 0 200 10-13-2013, 09:08 PM
Last Post: BruceH
  Using units in Numeric Solver Harold A Climer 1 249 10-13-2013, 10:44 AM
Last Post: Tim Wessman
  Meltiple Equation Solver PRIME Vs. HP 50G Harold A Climer 5 442 10-07-2013, 05:11 PM
Last Post: CR Haeger
  Does Prime Have a Multiple Equation Solver? Norman Dziedzic 2 277 09-20-2013, 09:43 AM
Last Post: Norman Dziedzic

Forum Jump: