Generating a complete sudoku puzzle w/ no reps

have random grid just need to check for reps..help plz

Page 1 of 1

9 Replies - 6181 Views - Last Post: 15 December 2008 - 10:56 AM Rate Topic: -----

#1 steelersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 08

Generating a complete sudoku puzzle w/ no reps

Posted 25 March 2008 - 10:29 AM

hi
im trying to create a sudoku puzzle that is 9x9 already completed and filled in with numbers having no rep in row, column, or smaller 3x3 grid. (just like the real deal sudoku puzzles)

here is what i have and it gives me a grid with repititions now just how would i turn this into a grid without repititions which is then a sudoku puzzle.

[code]
# include <iostream>
# include <ctime>
# include <iomanip>

using namespace std;

int random (int grid[][9], int i, int j)
{

srand(time(0));

for (i=0; i<9; i++)
{
for (j=0; j<9; j++)
{
grid[i][j] = rand()%9 + 1;
}
}
return 0;
}
[code]

this is merely a function that i link together for the entire program yes i have everything initialized and also grid is a 2D array.
how do i pass back the contents i then enter into the 2D array?? i have it just returning 0 because i don't know how to pass it back through.

Help will be much appriciated!
Thank you all!!

Is This A Good Question/Topic? 0
  • +

Replies To: Generating a complete sudoku puzzle w/ no reps

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 25 March 2008 - 10:33 AM

Instead of having your function generate all the values try making the function create single values and use a loop in main to assign the values into the array.
Was This Post Helpful? 0
  • +
  • -

#3 steelersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 25 March 2008 - 10:37 AM

Well my main function is only suppose to call the other functions and then the seperate functions are to do the calculating and assigning and then a print function will print
Was This Post Helpful? 0
  • +
  • -

#4 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Generating a complete sudoku puzzle w/ no reps

Posted 25 March 2008 - 10:37 AM

a finished sudoku is a latin square. google on that.
Was This Post Helpful? 0
  • +
  • -

#5 steelersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 25 March 2008 - 10:43 AM

Ok thanks but actually a latin square just has no reps in rows or columns while a sudoku puzzle has that and also no reps in each 3x3 grid as well
Was This Post Helpful? 0
  • +
  • -

#6 steelersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 25 March 2008 - 01:10 PM

does someone out there have any ideas? i know how to fill the grid with random numbers just how do i check previous numbers in the rows columns and sub-grids..the code i placed above does random fill
thanks
Was This Post Helpful? 0
  • +
  • -

#7 calico87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-February 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 26 March 2008 - 08:16 PM

View Poststeelersfan, on 25 Mar, 2008 - 10:37 AM, said:

Well my main function is only suppose to call the other functions and then the seperate functions are to do the calculating and assigning and then a print function will print


I usually lurk, but I play sudoku all the time and its a program i'm interested in.
post your main function and if you don't have your other functions calculations correct, give us what you have so one of us might help you finish it.

i'm not sure if this will help but I don't want to leave you without some form of help, so here is a link to an example sudoku program for you to see if any code is like yours. http://www.physics.o.../cpp/sudoku.cpp

hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#8 steelersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 27 March 2008 - 12:48 PM

thanks i think that helps me just it looks like thats checking if its valid after its filled in but what i need to do is check while it is placing the number in for better efficiency..so like what i need to do is somehow add another for loop to what i previously posted up above that some how assigns the number and then checks all numbers up til then for repetition and if there is none continue and if there is a repitition it needs to then search again

do you know what i mean..im going to try to work with that you showed me i think that will help me but if someone could know how to add a for loop into what i have above to then check for rep id appriciate it and that would work best and be the easiest

thanks
Was This Post Helpful? 0
  • +
  • -

#9 steelersfan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 27 March 2008 - 01:07 PM

even if someone can't help with the sudoku maybe just if someone might know how to check for repitition in just the row and help me with that then i could work off of that

thanks
Was This Post Helpful? 0
  • +
  • -

#10 siddude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-December 08

Re: Generating a complete sudoku puzzle w/ no reps

Posted 15 December 2008 - 10:56 AM

View Poststeelersfan, on 27 Mar, 2008 - 12:07 PM, said:

even if someone can't help with the sudoku maybe just if someone might know how to check for repitition in just the row and help me with that then i could work off of that

thanks


here is the function i thought for ur problem,hope it solves ur problem(9*9)

//to check solution is correct
void check()
{  int i=0,j=0,k=0,count=0;
int temp=0; 
int ch;

	for(i=0;i<9;i++)
	{
		for(j=0;j<9;j++)
		{
			temp=a[i][j];
				for(k=0;k<9;k++)
		{	
				if(temp==a[i][k])
				{
				count++;
				}
		}
	}

	if(count>1)
	cout<<"incorrect solution!"<<endl;
	cout<<"want to play again? "<<endl;
	cin>>ch;
		toupper(ch);   
	if(ch=='Y')
	generate();	// sudoku generator function 
	else
	exit();
}




you can use those code while the user is inserting the values or at the end when user is finished according to ur program
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1