Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hey,

I'm making this Sudoku in Unity3D project and I'm currently stuck on making the application check whether or not there are duplicate values in the specific row and column where the number has been inputted. I can provide the GenerateGrid script, so you can familiarise yourself with the code, as well as the way the subgrids are generated if needed.

I need to make the code:

- Check the columns to see that there are no duplicate values (no two of the same number in one grid)
- Check the rows to see that there are no duplicate values (no two of the same number in one grid)

What I have tried:

- Making 2 arrays, one for the rows and one for the columns
- Making 1 2D array for both the rows and the columns
Posted
Updated 12-Dec-21 5:02am
Comments
BillWoodruff 12-Dec-21 1:50am    
Hi, This question is specific enough i can help you with some specific code :)

First, i need to see/understand the code/strategy that creates the grid:

Are you binding the grid to a DataTable; or, creating it directly in a nested for loop ?

And, i believe you omit the case that you need to check for duplicates in a 3x3 sub-grid.

Are you looking for a generic solution for any size grid, or, only a solution for the classic Sudoku 3x3 sub-grids each 3x3 ?
Denis Hristov 12-Dec-21 3:23am    
Hey, not so sure about the first bit. (would have to consult with my teammates)

But I do want the code to be able to check for errors in any size grid, since the application we're making includes 3 difficulties. (Easy, Medium and Hard) While the difficulty only changes the size of the subgrids, (2x2, 2x3, 3x3) there is still a total of 4 subgrids on every level.

Hope that helps! :)
BillWoodruff 12-Dec-21 7:57am    
Hi, that partly clarifies the context for me, thanks, but, i define my role here as "educator," and, the idea of helping you write code for some project of which you are a team-member, and. you can't disclose details ... that is not the dance music my feet are keen to move to :)

A general solution to creating a grid of sub-grids, and then efficiently
accessing/selecting "cells" by any arbitrarily defined row, #rows, column, #columns, sub-grid, etc., is an interesting problem ... particularly, if you have nested sub-grids beyond 1 level deep.

In your case, i don't think you'll need to get recursive (deal with more than one level of sub-grids).

Depending on my energy level, I may post some general ideas about one strategy you might pursue.

cheers, bill
Denis Hristov 12-Dec-21 9:34am    
Hey, Bill

Thanks for replying and being so descriptive once again. I did in no way mean to ask you to write code for me, nor my teammates haha. I simply wanted someone to point me in the right direction, since we've been stuck on this for a while now and we haven't been able to get any help from other sources. Thank you in advance and I wish you a wonderful rest of your day! :)

1 solution

I assume you know how to iterate an array. In which case, if you use a Dictionary or List to "count" while iterating, you'll know when you have a duplicate (i.e. no existing entry, add the entry; if existing, it's a duplicate.)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900