This is a discussion on "Logic Problem involving loops and arrays" within the Other Programming Languages section. This forum, and the thread "Logic Problem involving loops and arrays are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Logic Problem involving loops and arrays
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Logic Problem involving loops and arrays
Hey everyone,
I am trying to create a sudoku solver in C. I am working on this one function that is supposed to go through each square and compare it to every other square, looking to see if the value in the square matches the value in any other square in its 3x3 grid, row, or column. puzzle[x][y] is the 2dimensional array containing each value that has been submitted. For example, puzzle[4][2] contains the value on column 4 and row 2... The code i am having a problem with is right here, where I want to test the current square to see whether it conflicts with the value in another square in either its 3x3 grid, row, or column.
|
|
|
|
#2
|
|||
|
|||
|
Re: Logic Problem involving loops and arrays
I been trying this out a bit but I'm not getting anywhere. That's one huge IF statement you got there
I'll get back to you when I have something to show!
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
#3
|
|||
|
|||
|
Re: Logic Problem involving loops and arrays
basically what it does is it loops through each row and column, then loops through each "other" row and column (signified by a and b instead of x and y). For each one, it tests whether the first square (x,y) contains similar values as in the other square (a,b). If it does, then it returns 0, if not, then it returns 1.
I am trying to figure out how to only test squares that are in its current row, in its current column, and in its current 3x3 grid. That is what the if statement is testing for. |
|
#4
|
|||
|
|||
|
Re: Logic Problem involving loops and arrays
i just realized something: I was mistakenly continuing if puzzle[x][y] != '0', when it should actually be if puzzle[x][y] == '0'..... since an input of '0' means that that is an empty square that the program should consider. If it isn't '0', the the program should stop at the current puzzle[x][y] and return -1 since it is already occupied by a number 1-9.
|
|
#5
|
||||
|
||||
|
Re: Logic Problem involving loops and arrays
Wow mind-boggling.
Is this solved now?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#6
|
|||
|
|||
|
Re: Logic Problem involving loops and arrays
no still not solved, but I wasn't expecting anyone to be able to do it or even devote enough time to understand it. It's a really complex problem.
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Free Flash music and ambient loops | equinoxsounds | Flash & Multimedia Forum | 3 | Oct 12th, 2007 09:57 |
| Limiting While Loops | Weird1993 | Databases | 5 | Jul 12th, 2007 04:33 |
| php While logic | dcarson | PHP Forum | 3 | Feb 7th, 2007 18:46 |
| Logic help | jayaime | JavaScript Forum | 4 | Aug 31st, 2006 14:28 |
| while loops? | mikegu | JavaScript Forum | 1 | Oct 26th, 2003 11:08 |