Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: ztrumpet on October 03, 2010, 06:14:59 pm

Title: Sudoku
Post by: ztrumpet on October 03, 2010, 06:14:59 pm
Here's the progress on a Sudoku program that I'm working on.  It's about 10% complete.  I need to know three things:
a) Who would want this?  I want to make it, so regardless, it's getting made. :P
b) Does anyone know where there's about 50 Sudoku puzzles that I could copy and put in the game?
c) What should the Menu have in it?  I have a couple of ideas, but I want to know what you guys think. :)

Thanks! ;D
Title: Re: Sudoku
Post by: Deep Toaster on October 03, 2010, 06:23:43 pm
I love sudoku!

Here's the progress on a Sudoku program that I'm working on.  It's about 10% complete.  I need to know three things:
a) Who would want this?  I want to make it, so regardless, it's getting made. :P
b) Does anyone know where there's about 50 Sudoku puzzles that I could copy and put in the game?
c) What should the Menu have in it?  I have a couple of ideas, but I want to know what you guys think. :)

Thanks! ;D

a) ME!
b) No, sorry.
c) Let's see... Undo, Mark, Quit, Save, Load, Custom, Solution (if you can).
Title: Re: Sudoku
Post by: nemo on October 03, 2010, 06:24:30 pm
a) meeeeee. sudoku's awesome.
b) here (http://www.websudoku.com/?select=1&level=1)
c) i have nothing :(
Title: Re: Sudoku
Post by: Deep Toaster on October 03, 2010, 06:26:08 pm
"Billions of Free Sudoku Puzzles" ... wow, sudoku's obviously got a lot of combos!

Not as many as the Rubik's Cube, of course ;)
Title: Re: Sudoku
Post by: nemo on October 03, 2010, 06:29:51 pm
yeah. and if you click the link to the "deluxe edition" or whatever they have 4x4, 6x6, 12x12, 16x16, and a couple variations of sudoku. but you have to download it.. and even then you only have a 60 minute trial until you have to pay money. i remember when i just started basic programming i wanted to make sudoku but didn't know how.
Title: Re: Sudoku
Post by: meishe91 on October 03, 2010, 06:38:59 pm
Looks really cool!

1. I want it ;D
2. I'm just gonna go with what nemo gave :P
3. Hmmm...save, load, restart, and new.
Title: Re: Sudoku
Post by: patriotsfan on October 03, 2010, 07:30:35 pm
Wow, awesome! Back then, I tried to make a sudoku solver but eventually I quit because I lacked the programming skills needed for such a task. :P Maybe I should start it again someday...

1. MEEEEEEE!!!
2. See nemo's suggestion above :P
3. New, Save, Load, Restart, Quit
Title: Re: Sudoku
Post by: DJ Omnimaga on October 04, 2010, 01:58:58 am
Looks nice. Unfortunately I'm not a fan of Sudoku, though, so I'm probably gonna pass on this one :(

Hopefully a lot of people will enjoy it :).
Title: Re: Sudoku
Post by: LordConiupiter on October 04, 2010, 03:12:39 am
nice!
1. I like puzzling, but i prefer programming :P
2. here is a generator (http://www.opensky.ca/~jdhildeb/software/sudokugen/)
3. New, Save, Load, How am I doing (HAID), Restart, Quit
Title: Re: Sudoku
Post by: Builderboy on October 04, 2010, 08:53:33 pm
How many sudoku are going to be preloaded?  Do you think an on calc generator is possible?  Are you going to scramble the preloaded so that it is even more random?

:D
Title: Re: Sudoku
Post by: ztrumpet on October 04, 2010, 08:55:40 pm
How many sudoku are going to be preloaded?
They will be 81 bytes each and I'm estimating 50 levels.
Do you think an on calc generator is possible?
I think it's possible, but I am unsure on size or speed.  I doubt if I'll include one in this program, though.
Are you going to scramble the preloaded so that it is even more random?
No.
:D
:D
Title: Re: Sudoku
Post by: Builderboy on October 04, 2010, 08:57:08 pm
Gotcha, why no scrambler?
Title: Re: Sudoku
Post by: ztrumpet on October 04, 2010, 08:57:52 pm
I don't know how one would work.  If you have some pseudo-code, then it's a possibility. :)
Title: Re: Sudoku
Post by: Builderboy on October 04, 2010, 09:22:26 pm
okay, with some rowswapping and that little t thing we can do this in no time :D

Code: [Select]
   012345678

0  000111222
1  000111222
2  000111222
3  333444555
4  333444555
5  333444555
6  666777888
7  666777888
8  666777888

Alright so here is our sudoku board.  Can you see that if we swap column 012 with 345 we dont change the solvability of the puzzle?  In addition, we can swap and group of 3 columns (012, 345 or 678) with any of the others and still maintain solvability.  In adition, we can swap column 0 with column 1, 1 with 2, or 0 with 2.  In any group of 3 (012,345, or 678) we can swap any of the single columns without making the puzzle any more difficult of unsolvable.  We can then use the fancy t thing, flip the matrix, and do the same thing with all the rows.  And as a final note, you can rotate a sudoku as much as you want and it doesn't do anything :D.  So all we need is swapping rows and flipping! Both have fast and built in routines to do that for us :)

So it would look something like this:

Code: [Select]
For(G,0,1)

  For(F,1,5)
    Rand(0,2)*3->I
    Rand(0,2)*3->J  //that *isnt* I
    Swap(I,J)
    Swap(I+1,J+1)
    Swap(I+2,J+3)
  End
  For(R,0,2)
    For(G,1,5)
      Rand(0,2)->I
      Rand(0,2)->J //that *isnt* I
      Swap(R*3+I,R*3+J)
    End
  End

  FlipMatrix

End

For(F,0,Rand(0,3)
  FlipMatrix
End


Should all work but its all theoretical!  XD
Title: Re: Sudoku
Post by: ztrumpet on October 04, 2010, 09:24:37 pm
OH!

I get it!  That's a very easy thing to do - I didn't realize I could do that.  I will certainly be implementing this!  Thanks Builderboy! ;D
Title: Re: Sudoku
Post by: Builderboy on October 04, 2010, 09:26:24 pm
Heh glad i could be of help :D That was a mighty fun post to write :)
Title: Re: Sudoku
Post by: ztrumpet on October 06, 2010, 05:41:13 pm
Challenge:
I've decided to attempt the unadvised:  Rotating strings.  The challenge is who can come up the the smallest and fastest routine in basic that turns this:
Quote
":
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999
:"  (line breaks added for clarity)
into this:
Quote
":
987654321
987654321
987654321
987654321
987654321
987654321
987654321
987654321
987654321
:"  (line breaks added again for clarity)

I will have a solution as well, but I want to see what you guys come up with. ;D  Good luck! :D
Title: Re: Sudoku
Post by: nemo on October 06, 2010, 06:16:27 pm
assuming the string is in Str1...

Code: [Select]
"   .one space
For(Z,-8,0
For(Y,9,1,-1
Ans+sub(Str1,9Y+Z,1
End:End
sub(Ans,2,81

i'd assume this is the way to go about it, but i'm looking up string commands on tibasic dev to see if there's a simpler way as i post this. i think this is the smallest... fastest is a different challenge.
Title: Re: Sudoku
Post by: meishe91 on October 06, 2010, 06:19:58 pm
Sounds like a UTI challenge problem :P

I'll see what I can come up with, though I bet Builder, nemo, or you will probably get it.

Edit:
See :P
Title: Re: Sudoku
Post by: nemo on October 06, 2010, 06:21:54 pm
would it be ok if the string rotated the other way?
 rather than:
Quote
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999
becoming
Quote
987654321
987654321
987654321
987654321
987654321
987654321
987654321
987654321
987654321
can it be


Quote
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
Title: Re: Sudoku
Post by: Builderboy on October 06, 2010, 06:33:33 pm
Yikes x.x string rotating?  Hurmm i will have to puzzle over this, but currently i cant see any way better than Nemo's.  Switching to strings for memory reasons i assume?
Title: Re: Sudoku
Post by: ztrumpet on October 06, 2010, 07:14:14 pm
Nemo, they can be flipped either way; I don't care. ;D
Thanks for that. :) I still have to come up with a routine of my own... 
Let's see how fast someone can make it! ^-^
Title: Re: Sudoku
Post by: meishe91 on October 06, 2010, 07:18:16 pm
Does the routine have to actually flip it or is it for a display routine? Because if it just has to be rotated when displayed then I could look at my routines from my spriter.
Title: Re: Sudoku
Post by: ztrumpet on October 06, 2010, 07:20:06 pm
It must be actually flipped. ;)
Title: Re: Sudoku
Post by: meishe91 on October 06, 2010, 07:20:48 pm
Dang, that means I actually have to experiment :P
Title: Re: Sudoku
Post by: Builderboy on October 06, 2010, 07:28:28 pm
So are you using Strings for memory reasons?
Title: Re: Sudoku
Post by: ztrumpet on October 06, 2010, 07:29:55 pm
Nah, it's for speed...
At least that's the plan.  I'll write both versions and then decide the one I like better. :)  Strings are much more flexible, though, and I like them better. ;D
Title: Re: Sudoku
Post by: Builderboy on October 06, 2010, 07:32:54 pm
Speed really? o.O But Matrices have a built in command for all the things you need silly :P
Title: Re: Sudoku
Post by: meishe91 on October 06, 2010, 07:36:48 pm
Would it be possible to store with strings and then put the chosen puzzle into a matrix and then use the built-in commands?
Title: Re: Sudoku
Post by: ztrumpet on October 06, 2010, 07:39:04 pm
Would it be possible to store with strings and then put the chosen puzzle into a matrix and then use the built-in commands?
Yes, and that's what I'll do if I use matrices.  However, I wanted to try strings too. ;D
Title: Re: Sudoku
Post by: meishe91 on October 06, 2010, 07:39:43 pm
Ah ok :P
Title: Re: Sudoku
Post by: Builderboy on October 06, 2010, 07:40:18 pm
Okay :) Well i cant come up with a better routine than nemo D: unless something tricky is hiding...
Title: Re: Sudoku
Post by: ztrumpet on October 06, 2010, 07:41:34 pm
Okay, then I dare you to only use Ans to hold the string!  (For loops may be used though...) ;D
Title: Re: Sudoku
Post by: meishe91 on October 07, 2010, 12:55:51 am
Ask and you shall receive :P

Code: [Select]
Str1
For(B,0,8
For(A,0,8
Ans+sub(Ans,9A+9-B,1
End
End
sub(Ans,82,81→Str2

Code: [Select]
Str1
For(B,0,8
For(A,0,8
Ans+sub(Ans,73+B-9A,1
End
End
sub(Ans,82,81→Str2

Str1 holds the original string to be rotated and then Str2 gets the new rotated string. I'm not sure if they can be optimized anymore, but I don't believe so.

Also, if you didn't figure it out. One rotates one way and the other rotates the other.