Hello I want to create a square matrix (NxN) that has this conditions:
1. It would be like a "1 square" sudoku, so if N=2, it would be
12 OR 21
21 12
because the numbers on each row and column cannot repeat, for N=3 it would be
123 and other combinations (it SHOULDNT always start with column 1,2,3.. or row 1,2,3.. all the matrix must be random
231
312
2. It has to work from N=2 to N=20 i tried this code
wf u 100
Subroutine Sudoku(scalar N)
matrix(N,N) Mat_Original
for !i=1 to N
for !j=1 to N
Mat_Original(!i,!j)=@round(@rnd*(N-1))+1
if !i>1 then
if !j>1 then
for !contador1=1 to !i-1
while Mat_Original(!i-!contador1,!j)=Mat_Original(!i,!j)
Mat_Original(!i,!j)=@round(@rnd*(N-1))+1
wend
next
for !contador2=1 to !j-1
while Mat_Original(!i,!j-!contador2)=Mat_Original(!i,!j)
Mat_Original(!i,!j)=@round(@rnd*(N-1))+1
wend
next
endif
endif
next
next
Endsub
Call Sudoku(4)
but it doesnt work (numbers keep getting repeated in each column, row for example my first column can be 1,2,2,4 .. so that's wrong, help please :( !!!
Question with a matrix
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Who is online
Users browsing this forum: No registered users and 2 guests
