Sudoku - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Sudoku (/thread-171632.html) |
Sudoku - kc - 09-07-2010 No, I am not talking about sophisticated programming techniques to solve sudoku puzzles. I like to solve by myself, but what I find out is that most of my solving time is "wasted" on figuring out what numbers are still available to be used on a particular cell. For example, if the row has 1 3 5, column has 1 4 6, the 9-square cell has 1 5 7, then I know that 2 8 9 is still available. One day I was sitting and thinking about writing an rpn program that, when I input those numbers already appeared (i.e. 135146157) (bear in mind that the same number may appear more than once), the program would return 289. I intially thought it would be easy (just counting numbers,right?), but then after some thoughts, I found it was not as easy as I originally thought! If somebody thinks it is just simple programming stuff and have some of your precious time to spare, would you please help me by providing me the program codes? Thanks a lot.
KC
Re: Sudoku - Ivan Nejgebauer - 09-07-2010 Quote: Quick'n'dirty: accumulate the sum of 10^(every digit of the input number); zeroes in the result denote unoccupied positions. The program is for the 15C, but won't work for arbitrary input values, since you simply can't enter a number longer than 10 digits.
LBL B Re: Sudoku - Norman Dziedzic - 09-07-2010 This is what I came up with on the 35s.
The test number is stored in A and B is cleared. B will hold the result number. Divide the test number modulo 10 to get the last digit and increment the indirect register based on this digit. Then divide the test number by 10, take the integer part and store back in A. At this point, indirect registers are filled with the frequencies of digits in the test number. Then loop through the indirect registers adding a digit to the output if the frequency is > 0. Use multiplies by 10 to shift left a digit.
001 LBL S Edited: 7 Sept 2010, 2:05 p.m.
Re: Sudoku - Norman Dziedzic - 09-07-2010 The program I posted does have the limitation of only recognizing the first 12 digits entered.
Re: Sudoku - Katie Wasserman - 09-07-2010 Here's my 12C code. Start with a <Clear Reg>, then enter numbers and hit R/S. You can enter at most 10 numbers at a time but you can keep running it and marking off more numbers, as long as you don't do a <Clear Reg>. It should work on any model 12C or 12C clone.
01 STO 0 [edited September 8: Tony(nz) found that two lines can be removed -- 10 is already in the Y register when (now) line 09 is executed.] [edited September 15: Tony(nz) found that three lines can be saved by rearranging the 2nd part of the code a bit and making use of a zero left in X from the 1st part of the code.]
Edited: 15 Sept 2010, 9:06 p.m. after one or more responses were posted
Re: Sudoku - kc - 09-07-2010 All you guys are so helpful. Thanks.
KC
Re: Sudoku - David Hayden - 09-11-2010 Here's a version in user RPL. You put a number containing the existing digits on the stack and then run the program. It replaces the top of stack with a number containing the digits not in the input number:
@ Given a number N, create a number with all Note that in a real sudoku solver it's much faster to store the possibilities as bits in a binary number and then use binary operations for logic like this. For example, in C code, you can gather up digits that are in a row like this:
int i;Experienced C programmers will recognize that this can be further simplified by using the "|=" operator.
Now that you have existingDigits, it's easy to get the missing digits, it's just the binary NOT of the existingDigits: int missingDigits = ~existingDigits;Note that this sets the bits that don't represent digits (e.g. bit 12). Re: Sudoku - Norman Dziedzic - 09-12-2010 David, You blew me away for efficiency. I haven't done any RPL programming so as an exercise, I put together a version of the 35s program that works with integers so no 12 digit limitation. I'll post it anyway for yucks. Start with a number on the stack, returns digits not in that number.
<< 0 -> n s Re: Sudoku - David Hayden - 09-12-2010 Here it is in C code for HPGCC. This takes a real or integer number on level 1 and replaces it with an integer containing the digits that aren't in the input number. Because it converts the number to a 64 bit binary number internally, integer inputs can be no more than 19 digits. Mostly, this is just a plug for the hpobjects library :).
// C program to figure the digits missing from a sudoku row/column/box. Re: Sudoku - Norman Dziedzic - 09-13-2010 David, Can I use hpgcc on a 48gii or only on a 50g?
Thanks
HPGCC on a 48gii - David Hayden - 09-13-2010 Hi Norman, Yes, you can get HPGCC to generate programs for a 48gii! If you do, then you and I will probably be the only people on the planet to have done it successfully. Here is how you do it:
First, you need HPGCC version 1.1. You can get it from the Install HPGCC 1.1 on your computer. In the rest of this message, I've assumed that you installed it into c:\arm-hp.
I had to add c:\arm-hp\libexec\gcc\arm-elf\3.4.6 to my path so the set HPGCC=C:\HPGCC1-1
The sat_createtemp() function that comes with HPGCC 1.1 doesn't work properly so you need to replace it with the one from HPGCC2.0 and rebuild the libraries. Here is the replacement file: // These functions replace sat_create_tempob() in HPGCC 1.1. They are takenCopy the above text into c:\arm-hp\sources\hplib\Saturn\sat_createtemp.c, replacing the existing file.
Edit c:\arm-hp\sources\hplib\hpmath.h and replace this line: #define _fabs(x) ( (x) < 0.0 ? (-x) : (x) )with this: #define _fabs(x) ( (x) < 0.0 ? -(x) : (x) )also replace this: #define abs(a) ((a) < 0 ? (-a) : (a))with this: #define abs(a) ((a) < 0 ? -(a) : (a))
Now rebuild the libraries as follows:
You need to install c:\arm-hp\ARMToolbox\LIB275-48.lib on your calculator. Note that you'll want to rename this library first because LIB275-48.LIB is an invalid variable name on the calculator.
It looks like the ArmToolbox's "S->exe" command isn't supported on the 48gii. You can only run programs via the PrRUN command. This means you can't create stand-alone programs on the HP48 - they require the ARMToolbox to be installed.
|