Sudoku Solver

Description

You have to save the starting puzzle in registers 8-16. Each row of the sudoku is represented as a single, 9 digit number, with 0 representing each blank. Once you have done that, you can run the program with a GSB A. When it is complete, you will find the solution to the sudoku puzzle in registers 17 to 25. You will need to use the indirect register to get at the result, because there is no way to directly see the value of register 20 and above.

Program resources

Labels

Name Description Name Description
A Sudoku Solver Main 3 Set the indirect register and remove the parameters from the stack
B Utility subroutine for setting flag matrix values 4 Extract value at the current column from the matrix indirectly specified by x&y
C Backs up to the previous position 5 Sets the utility temp register to 2^(x-1). Leaves x in place.
D Set/clear flag matrix values 6 Increments or decrements the current position in the trial solution.
E Main solution loop 7 Set the value x into the current row/column in the trial solution.
1 Returns the integer representing the entire Xth row of the flag matrix 8 Check the possible digits in order 1-9
2 Set the flags to show the input values are set 9 Get the appropriate row (x) from the flag matrix

Storage Registers

Name Description Name Description
0 General purpose variable used for miscelaneous purposes 5 Power of 10 of current column index
1 Current index (0-80) in the pseudo-recursion 6 Value in the test solution at current index
2 Row (0-8) of current index 7 Value of start clue at current index (0 if not set)
3 Column (0-8) of current index (i)
4 Block # (0-8) of current index I

Flags

Number Description
2 Indicates that a digit has been used in cur row/column/block
3 Input to Subroutine B (whether to set or clear flags)

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000    064 1   1 128 32 5   GSB 5
001 42.21.14 f LBL D 065 7   7 129 43. 5. 2   g CF 2
002 32 5   GSB 5 066 32 4   GSB 4 130 45 2   RCL 2
003 45 2   RCL 2 067 44 6   STO 6 131 32 9   GSB 9
004 32 12   GSB B 068 45 2   RCL 2 132 43. 6. 2   g F? 2
005 45 3   RCL 3 069 8   8 133 22 8   GTO 8
006 32 12   GSB B 070 32 4   GSB 4 134 45 3   RCL 3
007 45 4   RCL 4 071 44 7   STO 7 135 32 9   GSB 9
008 42.21.12 f LBL B 072 43 32 g RTN 136 43. 6. 2   g F? 2
009 32 1   GSB 1 073 32 3   GSB 3 137 22 8   GTO 8
010 45 0   RCL 0 074 45 24   RCL (i) 138 45 4   RCL 4
011 43. 6. 3   g F? 3 075 45.10. 5   RCL ÷ 5 139 32 9   GSB 9
012 16   CHS 076 43 44   g INT 140 43. 6. 2   g F? 2
013 40    077 1   1 141 22 8   GTO 8
014 34   x↔y 078 0   0 142 45 6   RCL 6
015 2   2 079 10   ÷ 143 32 14   GSB D
016 6   6 080 42 44   f FRAC 144 22 15   GTO E
017 32 3   GSB 3 081 1   1 145 42.21.13 f LBL C
018 44 24   STO (i) 082 0   0 146 1   1
019 33   R⬇ 083 20    147 16   CHS
020 9   9 084 43 32 g RTN 148 32 6   GSB 6
021 40    085 42.21.11 f LBL A 149 43.30. 1   g TEST x>0
022 22 5   GTO 5 086 43. 5. 2   g CF 2 150 22 13   GTO C
023 42.21. 7 f LBL 7 087 43. 5. 3   g CF 3 151 45 6   RCL 6
024 42. 4. 6   f x↔ 6 088 1   1 152 43. 4. 3   g SF 3
025 44 0   STO 0 089 16   CHS 153 32 14   GSB D
026 45 2   RCL 2 090 44 1   STO 1 154 43. 5. 3   g CF 3
027 1   1 091 42.21. 2 f LBL 2 155 22 8   GTO 8
028 7   7 092 1   1 156 42.21. 9 f LBL 9
029 32 3   GSB 3 093 32 6   GSB 6 157 32 1   GSB 1
030 45 24   RCL (i) 094 45 7   RCL 7 158 45.10. 0   RCL ÷ 0
031 45 6   RCL 6 095 32 7   GSB 7 159 43 44   g INT
032 45.30. 0   RCL 0 096 45 7   RCL 7 160 2   2
033 45.20. 5   RCL 5 097 43.30. 1   g TEST x>0 161 10   ÷
034 40    098 32 14   GSB D 162 42 44   f FRAC
035 44 24   STO (i) 099 8   8 163 43.30. 1   g TEST x>0
036 43 32 g RTN 100 0   0 164 43. 4. 2   g SF 2
037 42.21. 6 f LBL 6 101 45 1   RCL 1 165 33   R⬇
038 44.40. 1   STO 1 102 43.30. 6   g TEST x≠y 166 33   R⬇
039 45 1   RCL 1 103 22 2   GTO 2 167 9   9
040 45 1   RCL 1 104 1   1 168 40   
041 9   9 105 16   CHS 169 22 5   GTO 5
042 10   ÷ 106 44 1   STO 1 170 42.21. 5 f LBL 5
043 43 44   g INT 107 42.21.15 f LBL E 171 44 0   STO 0
044 44 2   STO 2 108 8   8 172 1   1
045 9   9 109 0   0 173 30   
046 20    110 45 1   RCL 1 174 2   2
047 30    111 43.30. 5   g TEST x=y 175 34   x↔y
048 44 3   STO 3 112 43 32 g RTN 176 14   
049 3   3 113 1   1 177 42. 4. 0   f x↔ 0
050 10   ÷ 114 32 6   GSB 6 178 43 32 g RTN
051 45 2   RCL 2 115 45 7   RCL 7 179 42.21. 1 f LBL 1
052 3   3 116 43.30. 1   g TEST x>0 180 36   ENTER
053 10   ÷ 117 22 15   GTO E 181 36   ENTER
054 43 44   g INT 118 32 7   GSB 7 182 2   2
055 3   3 119 42.21. 8 f LBL 8 183 6   6
056 20    120 9   9 184 32 3   GSB 3
057 40    121 45 6   RCL 6 185 45 24   RCL (i)
058 44 4   STO 4 122 43.30. 5   g TEST x=y 186 43 32 g RTN
059 8   8 123 22 13   GTO C 187 42.21. 3 f LBL 3
060 45.30. 3   RCL 3 124 1   1 188 40   
061 13   10ˣ 125 40    189 44 25   STO I
062 44 5   STO 5 126 32 7   GSB 7 190 33   R⬇
063 45 2   RCL 2 127 45 6   RCL 6 191 43 32 g RTN