473,508 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble with a Sudoku project.

1 New Member
We are writing a program to check that a filled in Sudoku puzzle is solved correctly. We are required to use the Iterator and Iterable interfaces. The program uses a Cell class to represent each individual cell of a puzzle, and uses a 2D array to represent the entire puzzle. The next method in our class that implements Iterator must return a Cell object array that stores the current row, column and box that we are checking. I have figured out how to store the correct row and column in the array, but having trouble figuring out how to store the correct values for the box. We have to be able to do this for any size Sudoku puzzle, our test cases are 4x4, 9x9, 16x16, and 25x25. What I have right now:

Expand|Select|Wrap|Line Numbers
  1. public class SudokuIterator implements Iterator<Cell []>
  2. {
  3.   private Cell[][] puzzle;
  4.   private int cursor;
  5.  
  6.   private SudokuIterator() {}
  7.  
  8.   public SudokuIterator(Cell[][] puzzle)
  9.   {
  10.     this.puzzle = puzzle;
  11.     cursor = 0;
  12.   }
  13.  
  14.   public boolean hasNext()
  15.   {
  16.     return cursor < puzzle.length;
  17.   }
  18.  
  19.   public Cell[] next()
  20.   {
  21.     Cell[] value = new Cell[2 * puzzle.length];
  22.  
  23.     for(int i = 0; i < value.length; i++)
  24.     {
  25.       if(i < puzzle.length) //sets the nth row
  26.         value[i] = puzzle[cursor][i];
  27.       else //sets the nth column
  28.         value[i] = puzzle[i - puzzle.length][cursor];
  29.     }
  30.  
  31.     cursor++;
  32.  
  33.     return value;
  34.   }
Not looking for exactly how to do it, just need some ideas to put me on the right track. Let me know if I need to be more clear on anything, and thanks for any help.
Oct 4 '09 #1
1 3248
r035198x
13,262 MVP
Browse the Java insights section on this site.
Oct 5 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2627
by: sub1ime_uk | last post by:
Thought I'd offer a method for solving all possible 9x9 sudoku puzzles in one go. It'll takes a bit of time to run however (and 9x9 seems to be about as big as is reasonably possible before...
5
9958
by: Stewart Gordon | last post by:
I have a few Sudoku puzzles on my site. http://www.stewartsplace.org.uk/mindbenders/ But adding extra columns and rows to separate the 3x3 blocks seems a rather kludgy approach, and the result...
11
4120
by: ago | last post by:
Inspired by some recent readings on LinuxJournal and an ASPN recipe, I decided to revamp my old python hack... The new code is a combination of (2) reduction methods and brute force and it is quite...
0
1417
by: Gary Stephenson | last post by:
Hi all, I am trying to work through the WPF example Sudoku app at http://msdn.microsoft.com/coding4fun/gaming/arcade/article.aspx?articleid=999502 Other than that I am using VS2005...
0
6718
by: JosAH | last post by:
Greetings, a couple of years ago a large part of the world went totally mad. Not because of global climate changes, not because of terrible wars that were started in the Middle East, nor because...
21
11345
by: ningxin | last post by:
Hi, i am currently taking a module in c++ in the university, and was given an assignment. because i have no prior background on the subject, everything is kind of new to me. i have tried for quite...
3
8585
by: deanchhsw | last post by:
Hello, I'm trying to build a program that solves sudokus and prints out the result on the screen. Here's the code for the class SudokuBoard. this will later be called in a class Sudoku. I'm a newbie,...
1
1847
by: deanchhsw | last post by:
Part A (http://bytes.com/topic/java/insights/645821-sudoku) B (http://bytes.com/topic/java/insights/739704-sudoku-b) C (http://bytes.com/topic/java/insights/739703-sudoku-c) this question refers...
3
5956
by: DannyB13 | last post by:
Hi, and thanks for possible help in advance. Here's my dilemma. I've been making a sudoku generator, and I'm now stuck on one part. I must be able to take a 'solution' and verify that it is correct,...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.