Reply to topic  [ 1 post ] 
Genius algorithm I created last night 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 7:35 pm
Posts: 6580
Location: Getting there
Reply with quote
I trying to come up with a way of parsing a string of any length to find a "sudoku definition" inside it.

A sudoku definition is a string of 81 numbers from 0 to 9 including ".". The zeroes and .s indicate blank squares.

What I really didn't want to do was start from each character and check the next 80 characters for an "incorrect" character. As this would mean parsing the entire string many times.

The solution I came up with was really quite good :D

In psuedo code...

Code:
while (i <= string.length - 81)
{
    get a substring from i of length 81.
   
    remove all sudoku characters from the substring.  (easy to do with a built in ObjC string function)
   
    if substring length = 0 then substring is a sudoku definition... return substring.
   
    if substring length > = then i += substring.length.
}


By doing it this way I could potentially be moving through the string 81 characters at a time. It only then starts to "slow down" when it begins to see a sudoku definition and will always find it :)

One thing I don't do is validate the grid but that is something maybe for the next version :)

I was really pleased with it though :D

_________________
Oliver Foggin - iPhone Dev

JJW009 wrote:
The count will go up until they stop counting. That's the way counting works.


Doodle Sub!
Game Of Life

Image Image


Tue May 01, 2012 7:55 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.