Code: Select all
Edit: Code updated.
See: http://kvince83.tengun.net/maxboard/viewtopic.php?p=61115#61115
or scroll down :)
In most cases for this program, size has more precedence than speed.
Moderator: MaxCoderz Staff
Code: Select all
Edit: Code updated.
See: http://kvince83.tengun.net/maxboard/viewtopic.php?p=61115#61115
or scroll down :)
Code: Select all
Repeat K
getkey->K
End
Code: Select all
Repeat Ans
getkey
End
Ans->K
Code: Select all
Line(7C-6,68-7B,7C-6,63-7B
Line(7C-1,68-7B,7C-1,63-7B
Code: Select all
For(Z,6,1,-5
Line(7C-Z,68-7B,7C-Z,63-7B
End
Code: Select all
:"Patz Calculator Sudoku V2
DelVar DDelVar HDelVar CgetKey ;not sure why you have this getKey
AxesOff
FnOff
ZoomSto
0→Xmin
0→Ymin
94→Xmax ;1→(triangle)X
62→YMax ;1→(triangle)Y
Vertical 0
Horizontal 0
Vertical 94 ;Vertical Xmax, size over speed..1 byte less, but takes a little more time
Horizontal 62 ;Horizontal Ymax, same as above
Horizontal 10
Horizontal 54
randInt(E5,E6-1→P
Text(1,2,"PATZ CALCULATOR SUDOKU V2
Text(11,9,"Start Game
Text(19,9,"Load Game
Text(27,9,"Difficulty: SIMPLE
Text(35,9,"Puzzle Number: ",P
Text(43,9,"Quit
Text(‾1,54,7,"Patrick Connor
Repeat K≤9
Text(8C+11,2,"{
Text(8C+11,5,">
Repeat K ;Repeat Ans, faster since you do not have to look into K each time as Ans is there and contains K
getKey→K
End
Text(‾1,8C+11,2," ;
C-(K=25)+(K=34→C ;could do C-(Ans=25)+(Ans=34:(Ans≠5)(Ans+5(Ans<0→C or combine both
(C≠5)(C+5(C<0→C
If max(K={21,105,22
Then
If K=22 or C=4 ;still working with C in Ans, so do Ans=4 instead
Goto Q ; I would suggest you restructure this code, as a memory leak will form when jumping outside a condition without ending it (doing the If ...:Then ...Goto 1 etc..)
If not(C ; same as above If not(Ans
1→K
If C=1
Then
85→dim(∟SUDO
; ∟SUDO, set in Ans..will save a few bytes and speed next line
If 462=Ans(1)+Ans(2)+Ans(3)+Ans(4
Then
Text(‾1,54,4," Load Game
identity(9→[I]
For(A,1,9
For(B,1,9
∟SUDO(9A+B-5→[I](A,B
End
End
∟SUDO(2→H
∟SUDO(3→P
∟SUDO(4→D
2→K
Else
Text(‾1,54,4," Invalid save!
End
DelVar ∟SUDO
End
If C=2
Then
Text(‾1,26,44,"
(D≠4)(D+1→D
Text(27,44,sub("SIMPLE EASY MEDIUM HARD SUICIDE",7D+1,7 ;D is in Ans, would set 7Ans+1 instead...size is the same, but a little faster..
End
If C=3
Then
DelVar PText(‾1,34,63,"
Repeat P>E5-1
Repeat Ans ;you do Repeat K up on top, but now you do as I suggested..stick to consistency ;)
getKey
End
Ans-91(Ans>91 and Ans<95)-78(Ans>81 and Ans<85)-65(Ans>71 and Ans<75)-102(Ans=102 ;you could get this smaller I will work later, and repost this line
If Ans<10 ;if they press something above key value 92 (0 key) you will have a problem, add a conditional If Ans>/=0 and Ans</=9 ;9, typing 10 cost another byte so it would work the same with doing </=9
10P+Ans→P
End
End
End
End
Text(‾1,54,4," Starting...
P→rand
If K=1
6-D→H
[[1,7,8,3,4,2,6,5,9][4,9,3,5,1,6,7,8,2][5,6,2,9,7,8,4,1,3][9,5,4,7,3,1,2,6,8][8,1,7,6,2,9,5,3,4][3,2
,6,8,5,4,1,9,7][7,8,5,2,6,3,9,4,1][6,3,1,4,9,7,8,2,5][2,4,9,1,8,5,3,7,6→[J] ;not sure if the whole matrix is here, but that wouldn't matter for me :P
For(A,0,1
[J]T→[J]
For(B,0,2
For(C,0,7
rowSwap([J],randInt(1,3)+3B,3B+randInt(1,3→[J] ;never worked with sudokus, looks like a nice routine throughout.
End
End
End
If K=1
Then
[J]→[I]
For(A,1,26+8D ;not sure how this works, as you have A in each loop..
For(A,1,26+8D
randInt(1,9→B
randInt(1,9→C
If [I](B,C ;C is in Ans, could replace C with Ans
Then
0→[I](B,C
Else
A-1→A
End
End
End
End
ClrDraw
;place 66 in Ans, will save you a byte but cost a little speed (not much)..
Text(1,66,"PATZ ;in Ans contains 66, then you can replace 66 with Ans
Text(7,66,"CALC ;Same as above
Text(13,66,"SUDOKU ;Same as above
Text(3,86,"V2
For(A,0,3
Vertical 21A
Line(0,21A-1,62,21A-1 ;well you could place 21A in Ans or 21A-1..if the first you would replace Vertical 21A with Vertical Ans and 21A-1 in both cases with Ans-1...saves 4 bytes either way..Could replace 62 with Ymax, saves a byte but cost a little speed (it looks up Ymax, where 62 is already there).
End
For(B,1,9
For(C,1,9
If [I](B,C
Text(7B-6,7C-5,[I](B,C ;I would use the same vars for temp vars (like B and C in all my for loops etc..
End
End
1→B
1→C
Text(23,68,"Puzzle
Text(29,69,P
Text(38,70,H," hints
Text(44,73,"left.
While [J]≠[I] ;can change this..not sure atm, not by calc and I am tired >.>
Line(7C-6,68-7B,7C-6,63-7B
Line(7C-1,68-7B,7C-1,63-7B ;well, I would either place in a for loop like posted above
Repeat K ;Repeat Ans, as stated before
getKey→K
End
K-91(K>91 and K<95)-78(K>81 and K<85)-65(K>71 and K<75→K ;K is in Ans, replace K's with Ans for speed and as before..I will post some code later for a optimized version..
If K=22 ;K is in Ans, replace K with Ans
Goto Q
If K=34 or (K≥24 and K≤26 ; same as above about K
Then
Line(7C-6,68-7B,7C-6,63-7B,0 ;same as above about a For() loop.
Line(7C-1,68-7B,7C-1,63-7B,0 ;""
C+(K=26 and C<9)-(K=24 and C>1→C ;K is still in Ans, can replace..also you could do this above (about combining the two up ahead)..
B+(K=34 and B<9)-(K=25 and B>1→B
End
If K=21 and Hnot([I](B,C
Then
[J](B,C→K
H-1→H
Text(38,70,H ;H is in Ans, replace H with Ans
End
If K=23
Then
0→[I](B,C
Text(7B-6,7C-5,"
End
If K<10 ;stated above about adding a conditional..
Then
K→[I](B,C
Text(7B-6,7C-5,K ;K is in Ans, replace
End
If K=31
Then
Text(57,70,"Saved!
{462-H-P-D,H,P,D→∟SUDO
For(A,1,9
For(K,1,9
[I](A,K→∟SUDO(9A+K-5
End
End
Text(‾1,55,70,"
End
End
ClrHome
Disp "","Congratulations!"," You finished"," puzzle "," on the","
Output(4,10,P
Output(6,5,sub(" SIMPLE EASY MEDIUM HARD SUICIDAL",8D+1,8
Pause " difficulty!! ;I like to replace Pause with Repeat getKey:End, great pause but works with any key (some do not know that you need to press enter >.>)
Lbl Q
ZoomRcl
AxesOn
ClrHome
FnOn
ClrDraw
DelVar [I]DelVar [J]Output(1,1,"
Code: Select all
DelVar DDelVar HDelVar CgetKey ;not sure why you have this getKey
Code: Select all
94→Xmax ;1→(triangle)X
62→YMax ;1→(triangle)Y
Code: Select all
Vertical 94 ;Vertical Xmax, size over speed..1 byte less, but takes a little more time
Code: Select all
Repeat K ;Repeat Ans, faster since you do not have to look into K each time as Ans is there and contains K
Code: Select all
C-(K=25)+(K=34→C ;could do C-(Ans=25)+(Ans=34:(Ans≠5)(Ans+5(Ans<0→C or combine both
Code: Select all
Text(27,44,sub("SIMPLE EASY MEDIUM HARD SUICIDE",7D+1,7 ;D is in Ans, would set 7Ans+1 instead...size is the same, but a little faster.
Code: Select all
If Ans<10 ;if they press something above key value 92 (0 key) you will have a problem, add a conditional If Ans>/=0 and Ans</=9 ;9, typing 10 cost another byte so it would work the same with doing </=9
Code: Select all
[[1,7,8,3,4,2,6,5,9][4,9,3,5,1,6,7,8,2][5,6,2,9,7,8,4,1,3][9,5,4,7,3,1,2,6,8][8,1,7,6,2,9,5,3,4]
[3,2,,6,8,5,4,1,9,7][7,8,5,2,6,3,9,4,1][6,3,1,4,9,7,8,2,5][2,4,9,1,8,5,3,7,6→[J] ;not sure if the whole matrix is here, but that wouldn't matter for me :P
Code: Select all
For(A,0,1
[J]T→[J]
For(B,0,2
For(C,0,7
rowSwap([J],randInt(1,3)+3B,3B+randInt(1,3→[J] ;never worked with sudokus, looks like a nice routine throughout.
End
End
End
Code: Select all
For(A,1,26+8D ;not sure how this works, as you have A in each loop..
Code: Select all
Text(7B-6,7C-5,[I](B,C ;I would use the same vars for temp vars (like B and C in all my for loops etc..
Code: Select all
Line(7C-1,68-7B,7C-1,63-7B ;well, I would either place in a for loop like posted above
Code: Select all
::"Patz Calculator Sudoku V2
:DelVar DDelVar HDelVar CgetKey
:AxesOff
:FnOff
:ZoomSto
:0→Xmin
:0→Ymin
:1→ΔX
:1→ΔY
:Vertical 0
:Horizontal 0
:Vertical 94
:Horizontal 62
:Horizontal 10
:Horizontal 54
:randInt(E5,E6-1→P
:Text(1,2,"PATZ CALCULATOR SUDOKU V2
:Text(11,9,"Start Game
:Text(19,9,"Load Game
:Text(27,9,"Difficulty: SIMPLE
:Text(35,9,"Puzzle Number: ",P
:Text(43,9,"Quit
:Text(‾1,54,7,"Patrick Connor
:Repeat K≤9
:Text(8C+11,2,"{
:Text(8C+11,5,">
:Repeat K
:getKey→K
:End
:Text(‾1,8C+11,2,"
:C-(Ans=25)+(Ans=34→C
:(Ans≠5)(Ans+5(Ans<0→C
:If max(K={21,105,22
:Then
:If K=22 or Ans=4
:Goto Q
:If not(Ans
:1→K
:If C=1
:Then
:85→dim(∟SUDO
:∟SUDO
:If 462=Ans(1)+Ans(2)+Ans(3)+Ans(4
:Then
:Text(‾1,54,4," Load Game
:identity(9→[I]
:For(A,1,9
:For(B,1,9
:∟SUDO(9A+B-5→[I](A,B
:End
:End
:∟SUDO(2→H
:∟SUDO(3→P
:∟SUDO(4→D
:2→K
:Else
:Text(‾1,54,4," Invalid save!
:End
:DelVar ∟SUDO
:End
:If C=2
:Then
:Text(‾1,26,44,"
:(D≠4)(D+1→D
:Text(27,44,sub("SIMPLE EASY MEDIUM HARD SUICIDE",7Ans+1,7
:End
:If C=3
:Then
:DelVar PText(‾1,34,63,"
:Repeat P>E5-1
:Repeat Ans
:getKey→K
:End
:Ans-91(Ans>91 and Ans<95)-78(Ans>81 and Ans<85)-65(Ans>71 and Ans<75)-102(Ans=102
:If Ans≤9
:10P+Ans→P
:Text(35,64,P
:End
:End
:End
:End
:Text(‾1,54,4," Starting...
:P→rand
:If K=1
:6-D→H
:[[1,7,8,3,4,2,6,5,9][4,9,3,5,1,6,7,8,2][5,6,2,9,7,8,4,1,3]
[9,5,4,7,3,1,2,6,8][8,1,7,6,2,9,5,3,4][3,2,6,8,5,4,1,9,7]
[7,8,5,2,6,3,9,4,1][6,3,1,4,9,7,8,2,5][2,4,9,1,8,5,3,7,6→[J]
:For(A,0,1
:[J]T→[J]
:For(B,0,2
:For(C,0,7
:rowSwap([J],randInt(1,3)+3B,3B+randInt(1,3→[J]
:End
:End
:End
:If K=1
:Then
:[J]→[I]
:For(A,1,26+8D
:randInt(1,9→B
:randInt(1,9→C
:If [I](B,C
:Then
:0→[I](B,C
:Else
:A-1→A
:End
:End
:End
:ClrDraw
:Text(1,66,"PATZ
:Text(7,66,"CALC
:Text(13,66,"SUDOKU
:Text(3,86,"V2
:For(A,0,3
:21A-1
:Vertical Ans+1
:Line(0,Ans,62,Ans
:End
:For(B,1,9
:For(C,1,9
:If [I](B,C
:Text(7B-6,7C-5,[I](B,C
:End
:End
:1→B
:1→C
:Text(23,68,"Puzzle
:Text(29,69,P
:Text(38,70,H," hints
:Text(44,73,"left.
:Repeat [J]=[I]
:Line(7C-6,68-7B,7C-6,63-7B
:Line(7C-1,68-7B,7C-1,63-7B
:Repeat K
:getKey→K
:End
:Ans-91(Ans>91 and Ans<95)-78(Ans>81 and Ans<85)-65(Ans>71 and Ans<75→Ans
:If Ans=22
:Goto Q
:If Ans=34 or (Ans≥24 and Ans≤26
:Then
:Line(7C-6,68-7B,7C-6,63-7B,0
:Line(7C-1,68-7B,7C-1,63-7B,0
:C+(Ans=26 and C<9)-(Ans=24 and C>1→C
:B+(K=34 and B<9)-(K=25 and B>1→B
:End
:If K=21 and Hnot([I](B,C
:Then
:[J](B,C→K
:H-1→H
:Text(38,70,Ans
:End
:If K=23
:Then
:0→[I](B,C
:Text(7B-6,7C-5,"
:End
:If K≤9
:Then
:K→[I](B,C
:Text(7B-6,7C-5,Ans
:End
:If K=31
:Then
:Text(57,70,"Saved!
:{462-H-P-D,H,P,D→∟SUDO
:For(A,1,9
:For(K,1,9
:[I](A,K→∟SUDO(9A+K-5
:End
:End
:Text(‾1,55,70,"
:End
:End
:ClrHome
:Disp "","Congratulations!"," You finished"," puzzle "," on the","
:Output(4,10,P
:Output(6,5,sub(" SIMPLE EASY MEDIUM HARD SUICIDAL",8D+1,8
:Pause " difficulty!!
:Lbl Q
:ZoomRcl
:AxesOn
:ClrHome
:FnOn
:ClrDraw
:DelVar [I]DelVar [J]Output(1,1,"
Code: Select all
A - Most used temporary variable
B - Multiple use variable
Before gameplay, it is a general use FOR counter.
During gameplay, it is used as the cursor's ROW
C - Multiple use variable
(C)ommand chosen in Main Menu
Temporary (c)ounter variable
(C)olumn currently in use
D - Puzzle difficulty number (0=Simple ... 4=Suicidal)
H - Hints left (0-6)
K - Multiple use temporary variable
In the main menu, if Start or Load game are selected, then this variable will become 1 or 2.
It is generally used as a getKey storage in other cases.
Also used in the Save Game feature
P - Puzzle number (100000-999999)
lSUDO - Save game file
Elem. Use
1 Verify's save game validity. (see source code)
2 Hints left
3 Puzzle number
4 Puzzle difficulty
5-85 Puzzle layout
[J] - Completed puzzle
[I] - User's puzzle
Total number of variables used: 10
7 Reals
1 (optional) List
2 Matrices
Code: Select all
:ZStandard
:84→Xmin
:52→Ymin
:ZInteger
Code: Select all
:C-(Ans=25)+(Ans=34
Code: Select all
:Ans-102(Ans=102)-13int(Ans/13(2>abs(5-abs(5-abs(Ans-83
Code: Select all
:rowSwap([J],1+int(3rand)+3B,3B+1+int(3rand→[J]
Code: Select all
:1+int(9rand→B
:1+int(9rand→C
Code: Select all
:Ans-13int(Ans/13(2>abs(5-abs(5-abs(Ans-83
Code: Select all
:If max(Ans={24,25,26,34
Code: Select all
:max(1,min(8,C+(Ans=26)-(Ans=24→C
:max(1,min(8,B+(K=34)-(K=25→B
Code: Select all
:{462-H-P-D,H,P,D→SUDO
Code: Select all
:ZStandard
:84→Xmin
:52→Ymin
:ZInteger
Code: Select all
:C-(Ans=25)+(Ans=34
Code: Select all
:Ans-102(Ans=102)-13int(Ans/13(2>abs(5-abs(5-abs(Ans-83
Code: Select all
:Ans-13int(Ans/13(2>abs(5-abs(5-abs(Ans-83
Code: Select all
:rowSwap([J],1+int(3rand)+3B,3B+1+int(3rand→[J]
Code: Select all
:1+int(9rand→B
:1+int(9rand→C
Code: Select all
:If max(Ans={24,25,26,34
Code: Select all
:max(1,min(8,C+(Ans=26)-(Ans=24→C
:max(1,min(8,B+(K=34)-(K=25→B
Code: Select all
:{462-H-P-D,H,P,D→SUDO