Member 13815170
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)