The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

Sudoku Solver for HP-33s
Message #1 Posted by Marcel Samek on 10 May 2012, 12:35 p.m.

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

      
Re: Sudoku Solver for HP-33s
Message #2 Posted by bill platt on 10 May 2012, 1:03 p.m.,
in response to message #1 by Marcel Samek

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

      
Re: Sudoku Solver for HP-33s
Message #3 Posted by Matt Agajanian on 10 May 2012, 3:25 p.m.,
in response to message #1 by Marcel Samek

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.

            
Re: Sudoku Solver for HP-33s
Message #4 Posted by Lode on 11 May 2012, 3:01 p.m.,
in response to message #3 by Matt Agajanian

MS Excel? :/

Why not Matlab?


[ Return to Index | Top of Index ]

Go back to the main exhibit hall