Jump to content




[Project Idea]Sudoku


  • You cannot reply to this topic
23 replies to this topic

#1 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 10 March 2013 - 05:38 PM

I think it's about time for someone to make Sudoku in CC! Who's up for the challenge? I'm talking selective difficulties, random number generation, the whole 9 yards! I'm no pro at the Math Library so I would never dare to take on such a task. ^_^ I'm also aware Orwell has made a sudoku generator, maybe one could use that and take it to the next level.

#2 Azhf

  • Members
  • 180 posts
  • LocationMurrika

Posted 10 March 2013 - 05:52 PM

lol whoever accepts good l;uck

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 10 March 2013 - 07:09 PM

Actually, this is not a bad idea. If I were any good at sudoku i might take a stab at it, but i'm not super interested in destroying my mind with math.

#4 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 10 March 2013 - 07:53 PM

Why hasn't this been done yet. Now, I'm not aware of the complexity of the maths, but I'm gona take a stab at it.

#5 BigSHinyToys

  • Members
  • 1,001 posts

Posted 10 March 2013 - 08:02 PM

I'm thinking a lot of math.random() should do it I will also be trying this ... ow and yes I'm still here just not as active (work / life / other interferences.) You know how it is.

#6 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 10 March 2013 - 08:11 PM

View PostCranium, on 10 March 2013 - 07:09 PM, said:

Actually, this is not a bad idea. If I were any good at sudoku i might take a stab at it, but i'm not super interested in destroying my mind with math.

Counting to 9, real difficult math. :P/>

I wish everyone who tries this the best of luck!

#7 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 10 March 2013 - 08:20 PM

I tried. The first algorithm I came up with would get stuck 90 percent of the time, because of situations like this:

. . . . . . . . 1
. . . . . . . . 2
. . . . . . . . 9
. . . . . . . . 4
1 2 3 4 5 6 7 8 ?

The code basically goes through the current row, column, and box it's in, and finds all possible numbers that can fit in that box, then throws in a random number from those possibilities. However here, you see the only possibility for the fifth row is 9, yet that's already taken in the 9th column.

My second algorithm, choosing a bunch of random rows while continually checking if it fits the puzzle, works, but is slow as hell. Takes 30 seconds to make one puzzle, and that's without checking boxes of 3x3.
Good luck to whoever can take this on and succeed better than I could.

#8 BigSHinyToys

  • Members
  • 1,001 posts

Posted 11 March 2013 - 12:08 AM

View PostKingdaro, on 10 March 2013 - 08:20 PM, said:

I tried. The first algorithm I came up with would get stuck 90 percent of the time, because of situations like this:

. . . . . . . . 1
. . . . . . . . 2
. . . . . . . . 9
. . . . . . . . 4
1 2 3 4 5 6 7 8 ?

The code basically goes through the current row, column, and box it's in, and finds all possible numbers that can fit in that box, then throws in a random number from those possibilities. However here, you see the only possibility for the fifth row is 9, yet that's already taken in the 9th column.

My second algorithm, choosing a bunch of random rows while continually checking if it fits the puzzle, works, but is slow as hell. Takes 30 seconds to make one puzzle, and that's without checking boxes of 3x3.
Good luck to whoever can take this on and succeed better than I could.
I am having the same problem
my code so far.
It generates a game with nil elements because it runs out of possibility.
http://pastebin.com/UWpYhmvR
and with that I have no idea where to turn ??

#9 Kryptanyte

  • Members
  • 95 posts
  • LocationNew Zealand

Posted 11 March 2013 - 01:40 AM

Couldn't you just make a random generation of numbers for vert or horizontal lines then insert the opposite (aka if you generated horizontal random number lines then you insert vertical lines) into a table, like;

123
312
231

We end up with 6 tables;

Horizontal Tables:
hLine1 = {1,2,3}
hLine2 = {3,1,3}
hLine3 = {2,3,1}

Vertical Tables:
vLine1 = {1,3,2}
vLine2 = {2,1,3}
vLine3 = {3,2,1}

Then if runs checks with each table, looking for double ups or even triple ups, then looks for what numbers are missing in that particular line. Taking said variables from the checks it regenerates the numbers with an algorithm designed to take both X and Y axis and figure out which particular number can fit in both at a certain point.

My method could just be over thought and I can see some issues when running an algorithm for the redrawing of numbers, for example you might have nothing that can fit in both lines because you have something like
1
1,2,3,0,5,6,7,8,9
3
4
5
6
7
8
9

Where there is the number 4 missing in the X line but in the Y the number 2 is missing.

Again, its just my train of thought on how to do this, I'm not really thinking about it too hard, too early in the morning

#10 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 11 March 2013 - 02:24 AM

The way I would do this is generate a 3x3 cell at random, check if it is possible, if so: put it in, if not: generate a new cell.
Repeat untill youve got 9 valid cells..
Then remove random numbers to complete the puzzle.
this would give 2 problems:
It is not certain if the puzzle is solvable (you would need to make a sudoku solver to check this)
It is not certain if there is only one solution (this would need an even more advanced sudoku solver)

I will have to try this method out soon...

#11 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 11 March 2013 - 04:19 AM

Lol, i'm glad everyone is trying their luck at this. I wish you all the best of luck ^_^

#12 BigSHinyToys

  • Members
  • 1,001 posts

Posted 11 March 2013 - 04:46 AM

The way I trying was having a table with 1 to 9 for each row and column and box then testing what numbers are valid for each X,Y then making those false in the row / column / box tables so next time that number wont be picked. then randomly picking from the available numbers. the problems is don't work and ends up with no possible numbers for some squares ?? kinda random.

Maybe the fresh light of day will help.

#13 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 11 March 2013 - 05:02 AM

You guys should take a look at this. Although it is written in Visual Basic (?), he has a good method for generating puzzles.

#14 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 11 March 2013 - 05:04 AM

Well like I said, Orwell made a generator. So i'm not sure if you could use that, then take a few numbers away. Have all the numbers (1-9) at the bottom, so when they click that number, then click a box, that number will appear.

#15 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 11 March 2013 - 05:35 AM

View PostBubba, on 11 March 2013 - 05:02 AM, said:

You guys should take a look at this. Although it is written in Visual Basic (?), he has a good method for generating puzzles.

I'd port this if I knew VB. Visual Basic's Syntax Reminds Me Of Those People Who Capitalize The First Letter Of Every Word They Say.

#16 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 11 March 2013 - 07:15 AM


This (quite interesting) video shows some of the requirements for a valid sudoku puzzle..
EDIT: so now that we know what to keep in mind when creating a sudoku, and we have ourselves a valid sudoku generator (Orwell's generator uses the method described be bubba's link), the next step is to make the valid sudoku grid into a puzzle!
So we can erase numbers (or make them invisible) untill at least 17 numbers remain, of which 1 number is part of the magic pair or whatever numberphile called it..

#17 Kryptanyte

  • Members
  • 95 posts
  • LocationNew Zealand

Posted 13 March 2013 - 01:08 AM

Call me crazy, but Challenge Accepted.

It won't be pretty and anyone who is actually good at LUA will probably think what the hell am I doing with random lines of useless code everywhere.

#18 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 13 March 2013 - 03:22 AM

View PostKryptanyte, on 13 March 2013 - 01:08 AM, said:

Call me crazy, but Challenge Accepted.

It won't be pretty and anyone who is actually good at LUA will probably think what the hell am I doing with random lines of useless code everywhere.

The hardest part is going to be writing an algorithm to make sure the puzzle is actually solvable.

#19 Kryptanyte

  • Members
  • 95 posts
  • LocationNew Zealand

Posted 13 March 2013 - 07:41 AM

Well according to numberphile all you need is 17 numbers, there is no need to have specific ones except when you get an "Unavoidable Square" when there are two pairs numbers exactly the same on the same lines but flipped so like:

425
168
973
-----
842
791
356

See the 9 and the 7? thats what I mean

#20 Kryptanyte

  • Members
  • 95 posts
  • LocationNew Zealand

Posted 15 March 2013 - 12:16 AM

Double post bump with help request?
http://www.computerc...or-double-data/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users