`int[,,] solver = new int[9,9,9];`

Go forth, and code.

See more:

Hello!

I try to do a program which solves a 3d sudoku (9x9x9, 9 soduko table in row, behind each other) and the first thing is doing the first sudoku table, then the second and so on. I did it, and then the next task is rotate it, or flip it in vertical, or in horizontal until i get a valid 3d sudoku, so the numbers in the rows and the columns don't contain 2 same number. So the rules of soduko.

Any idea to do it?

What i have currently:

-Solves the 9 sudoku table

-It can rotate the table

-It can flip it

What I tried:

-I made a lot "for" to go through all possible solutions.(ye, i know, thats a very very stupid idea, but first I wanted it to see working perfectly) I started it about an hour ago, and it still works, as I calculated it has 300 billion possible solutions, so yes it will take a few hours to go through.

My question is, how could I do this? What's your idea?

Thanks for the answers.

I try to do a program which solves a 3d sudoku (9x9x9, 9 soduko table in row, behind each other) and the first thing is doing the first sudoku table, then the second and so on. I did it, and then the next task is rotate it, or flip it in vertical, or in horizontal until i get a valid 3d sudoku, so the numbers in the rows and the columns don't contain 2 same number. So the rules of soduko.

Any idea to do it?

What i have currently:

-Solves the 9 sudoku table

-It can rotate the table

-It can flip it

What I tried:

-I made a lot "for" to go through all possible solutions.(ye, i know, thats a very very stupid idea, but first I wanted it to see working perfectly) I started it about an hour ago, and it still works, as I calculated it has 300 billion possible solutions, so yes it will take a few hours to go through.

My question is, how could I do this? What's your idea?

Thanks for the answers.

Comments

!

Never post fake answers! I deleted yours, but did not delete your question yet!

I think you would just need a triple-subscripted array.

Go forth, and code.

`int[,,] solver = new int[9,9,9];`

Go forth, and code.

Comments

1. Sudoku table: [0,0] is 1

2. Sudoku table: [0,0] is 1

(and so on... to 9, then check it again with [0,1] and so on)

So thats wrong, because there are two of 1. Then rotate, or flip another sudoku table again, and do it while it isn't correct.

I hope you could understand me:)

I dont know, if I understand the question, but i started programming generator of 3D sudoku 2x2x2. It has numbers 1-8 in it. Its big cube 8x8x8, it has LINES and COLUMNS, each of them has numbers 1-8. There are also VERTICAL LINES from bottom up. And SMALL CUBES 2x2x2, which has numbers 1-8 too. (2D sudoku have only columns, lines and small squares) This puzzle has got 512 numbers. Program is made in python 3. My program generate array with 512 numbers. Those are the numbers in the puzzle. You can count their indexes as (x + y*8 + z*64). The program starts with array in array: sudokulist = [[3,4,5,6,8,1,2,7]] sudokulist is array, with all sudokus. The program tries to add all posibilities of numbers to the sudoku and create more sudokus in sudokulist. It will add only correct sudokus. Example how it could generate 2D sudoku 1x2:¨ [[]] [[1][2]] [[1,2][2]] [[1,2,2][2]] [[1,2,2,1][2]] This example program generated one of 2 possible solutions of sudoku 1x2 (the sudoku with 2 wasnt used, couse the program ended really fast, but the real one shuffle sometimes the sudokus): 12 21 21 AND 12 The REAL program sometimes delete some sudokus, so there wont be too many. This is why it always when i use it, it can generate only about 310 long sudoku. (once it hits 448 it will always find one correct solution with 512 numbers, couse the last 64 numbers have only one solution (or I hope so, it works with all 2D sudokus, where the last column i generated always had one good posibility)) IF YOU HAVE ANY SUGGESTIONS HOW TO GENERATE IT SOMEHOW, YOU CAN HELP ME OR SORRY FOR INTERRUPTIONG YOUR FORUM. NOONE EVER GENERATED ANY 3D SUDOKU I KNOW ABOUT, SO I MAY BE THE FIRST. :D #PROGRAM SUDOKU 2X2X2 --- GENERATING from copy import deepcopy from random import shuffle #set first line to random numbers 1-8, becouse these numbers arent important def start(): sudoku = [] for i in range(1, 9): sudoku.append(i) shuffle(sudoku) sudokulist = [] sudokulist.append(sudoku) return(sudokulist) #sudokulist is array with all the sudokus in it sudokulist = [] longest = 0 #add one number to the sudoku while True: #if the sudokulist is empty (all correct solutions were deleted due to ) if len(sudokulist) == 0: print("RESTART", longest) sudokulist = start() longest = 0 #this part of code delete some sudoku from sudokulist, so the memory wont overload #if limit high - slow program, if low - high chance of not getting any sudoku if len(sudokulist) > 50000: shuffle(sudokulist) for i in range(0, 10000): sudokulist.pop(0) #set sudoku to sudokulist[0], remove sudokulist[0] sudoku = deepcopy(sudokulist[0]) sudokulist.pop(0) #try to add numbers 1-8 to the sudoku (last = number you are adding) for last in range(1, 9): #set x,y,z (positions of the number you are adding) position = len(sudoku) x = position % 8 position = round((position - x) / 8) y = position % 8 position = round((position - y) / 8) z = position % 8 correct = True #if last already exist in LINE, the program will delete the sudoku for i in range(0, x): if sudoku[z*64 + y*8 + i] == last: correct = False #if last already exist in COLUMN, the program will delete the sudoku for i in range(0, y): if sudoku[z*64 + i*8 + x] == last: correct = False #if last already exist in VERTICAL LINE, the program will delete the sudoku for i in range(0, z): if sudoku[i*64 + y*8 + x] == last: correct = False #if last already exist in 2x2x2 CUBE, the program will delete the sudoku base = (z - z % 2)*64 + (y - y % 2)*8 + (x - x % 2) above = len(sudoku) - base if above > 9: if sudoku[base] == last or sudoku[base + 1] == last or sudoku[base + 8] == last or sudoku[base + 9] == last: corect = False above -= 64 base += 64 if above > 1: if sudoku[base] == last or sudoku[base + 1] == last: correct = False above -= 8 base += 8 if above == 1: if sudoku[base] == last: correct = False #if the program didnt find last already exist in any object already add it to the sudokulist if correct: sudokuadd = deepcopy(sudoku) sudokuadd.append(last) sudokulist.append(sudokuadd) if len(sudokuadd) > longest: longest += 1 #this part controlls if the program do any progress print the longest sudoku found if longest % 30 == 0: print(longest)

One posible sudoku 2x2x2 here. I created it only with my mind, but it is symetrical.

These are 8 tables of 8x8 numbers. You choose one table 8x8, which has all numbers in each line, column and 2x2 square. I chose:

12 34 56 78

34 12 78 56

56 78 12 34

78 56 34 12

21 43 65 87

43 21 87 65

65 87 21 43

87 65 43 21

The tables are symetrical to each other too.

>>>

To every even table add +4 to every number. If too high, remove -8.

To every uneven table add +1. If too high, remove -8.

>>>

Example sudoku 2x2x2:

12345678

34127856

56781234

78563412

21436587

43218765

65872143

87654321

56781234

78563412

12345678

34127856

65872143

87654321

21436587

43216378

23456781

45238167

67812345

81674521

32547618

54321876

81674523

54327618

67812345

81674523

23456781

45218167

76183254

18765432

45238167

76185432

34567812

56341278

78123456

12785634

43658721

34652187

87214365

21876543

78123456

12785634

34567812

56341278

87214365

21873465

43658721

65432187

45678123

67452381

81234567

23816745

54762381

76543218

18325476

32187654

81234567

23816745

45678123

67452381

23815476

32187654

54761832

76543218

These are 8 tables of 8x8 numbers. You choose one table 8x8, which has all numbers in each line, column and 2x2 square. I chose:

12 34 56 78

34 12 78 56

56 78 12 34

78 56 34 12

21 43 65 87

43 21 87 65

65 87 21 43

87 65 43 21

The tables are symetrical to each other too.

>>>

To every even table add +4 to every number. If too high, remove -8.

To every uneven table add +1. If too high, remove -8.

>>>

Example sudoku 2x2x2:

12345678

34127856

56781234

78563412

21436587

43218765

65872143

87654321

56781234

78563412

12345678

34127856

65872143

87654321

21436587

43216378

23456781

45238167

67812345

81674521

32547618

54321876

81674523

54327618

67812345

81674523

23456781

45218167

76183254

18765432

45238167

76185432

34567812

56341278

78123456

12785634

43658721

34652187

87214365

21876543

78123456

12785634

34567812

56341278

87214365

21873465

43658721

65432187

45678123

67452381

81234567

23816745

54762381

76543218

18325476

32187654

81234567

23816745

45678123

67452381

23815476

32187654

54761832

76543218

v3

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