• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sudoku  RSS feed

 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, the thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value).

Please Help.

my assignment is to get a solved sudoku for these values:


My current code

 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does not correctly check for solved

What if the starting grid had the entire bottom row filled in, the entire right column, and the entire lower-right square, but all others were zero?

I noticed that in some places you had grid[x][y] and in other grid[y][x].
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You will be pleased to know that puzzle has a solution and it is simple to solve.
Please explain your program: what algorithm does it use to solve the puzzle? Also why are you using the keyword static so often? We can only help if we know the algorithm.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross posted here and here. Please read -->BeForthrightWhenCrossPostingToOtherSites
 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

You will be pleased to know that puzzle has a solution and it is simple to solve.
Please explain your program: what algorithm does it use to solve the puzzle? Also why are you using the keyword static so often? We can only help if we know the algorithm.


Thanks

my teacher asked us to make a sudoku that solves the puzzle when the following input is entered. he also asked us to do this with static method.


i tried to write a code, but it gives me an error, by error i mean i doesn't show anything on the output screen, when i place the following input in my current coding.
tho my code works great on null grid.
 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:This does not correctly check for solved

What if the starting grid had the entire bottom row filled in, the entire right column, and the entire lower-right square, but all others were zero?

I noticed that in some places you had grid[x][y] and in other grid[y][x].


thanks for pointing that out, i'll fix it, and will let you know if it worked.
 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Cross posted here and here. Please read -->BeForthrightWhenCrossPostingToOtherSites


my apologies, i thought SOMEONE will help me (didn't know i will get help/replies from every single site). I have closed the other threads i have created on the other sites.
I'm new to this forums thing and new to java as well.

it won't happen again.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted

Did your teacher say why you should use static methods?
 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Apologies accepted

Did your teacher say why you should use static methods?


maybe he had in his mind that we will work with multiple classes, so as you know its easier to call static method rather than a creating an obj for normal method.

tho i have only used one class, so it might look odd, but i thought i should work on static even if i'm working in just one class.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Highly unlikely explanation.
The one good explanation for those methods being static that I can think of is that you were supposed to write in a functional style.
 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but the thing is what is wrong with my current coding, that its not giving an out for certain grid.?

if you can help me with that please do. I'll be very thankful for your help.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Syed Irtaza wrote:but the thing is what is wrong with my current coding, that its not giving an out for certain grid.?


Well, I am assuming that it does print the original grid, right? The issue is that it is not printing the result?

Question. How is it not printing the result?

If the program is just ending, and returning to the command prompt, then it is likely that the arrays got corrupted; and somehow, they become zero length. If the program is not returning at all, meaning it just doesn't seem to be doing anything at all, then it is likely that you have an issue with your recursion code, in that it is doing something endlessly. In either case, you need to debug it. Add some print statements, to try to follow it, to try to see what is going on.

Henry
 
Syed Irtaza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Syed Irtaza wrote:but the thing is what is wrong with my current coding, that its not giving an out for certain grid.?


Well, I am assuming that it does print the original grid, right? The issue is that it is not printing the result?

Question. How is it not printing the result?

If the program is just ending, and returning to the command prompt, then it is likely that the arrays got corrupted; and somehow, they become zero length. If the program is not returning at all, meaning it just doesn't seem to be doing anything at all, then it is likely that you have an issue with your recursion code, in that it is doing something endlessly. In either case, you need to debug it. Add some print statements, to try to follow it, to try to see what is going on.

Henry


it is printing the original grid, but when i alter the grid.. like adding more that 4 int values in diff places of the userGrid, the program runs endlessly.
alright i'll try to figure out if there is any problm with my recursion.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting this just inside your loop() method:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!