PROBLEMAS CON MATRIZ
Publicado por martín (74 intervenciones) el 16/02/2010 14:13:20
Hola:
Inserto el código fuente de una matriz que no debe repetir los numeros (0 al 9) ni en las lineas verticales ni en la horizontales. Como podeis ver, las 5 últimas sentencias de REPETICION están desactivadas, pues de estar todas activadas no se produce la matriz o rara vez se produce, y ese es my problema, desdeluego, no faltaba mas. Agradezco infinitamente la ayuda que me puedan prestar:
program Sin_repeticion_en_vectores;
uses crt;
type
digitos = set of 0..9;
var
t : array[1..9,1..9] of integer;
x,y,i,j,n,p,q,gd,gm : integer;
a,b,c,d,e,f,g,h,k,l : digitos;
begin
randomize;
a := [];
b := [];
c := [];
d := [];
e := [];
f := [];
g := [];
h := [];
k := [];
l := [];
for y := 1 to 9 do
begin
repeat
t[1,y] := random(10);
n := t[1,y]
until ((n in h)=false) and ((n in a)=false);
include(h,n); include(a,n);
repeat
t[2,y] := random(10);
n := t[2,y]
until ((n in h)=false) and ((n in b)=false);
include(h,n); include(b,n);
repeat
t[3,y] := random(10);
n := t[3,y]
until ((n in h)=false) and ((n in c)=false);
include(h,n); include(c,n);
repeat
t[4,y] := random(10);
n := t[4,y]
until ((n in h) = false) and ((n in d) = false);
include(h,n); include(d,n);
{repeat
t[5,y] := random(10);
n := t[5,y]
until ((n in h) = false) and ((n in e) = false);
include(h,n); include(e,n);
repeat
t[6,y] := random(10);
n := t[6,y]
until ((n in h) = false) and ((n in f) = false);
include(h,n); include(f,n);
repeat
t[7,y] := random(10);
n := t[7,y]
until ((n in h) = false) and ((n in g) = false);
include(h,n); include(g,n);
repeat
t[8,y] := random(10);
n := t[8,y]
until ((n in h) = false) and ((n in k) = false);
include(h,n); include(k,n);
repeat
t[9,y] := random(10);
n := t[9,y]
until ((n in h) = false) and ((n in l) = false);
include(l,n);}
h := []
end;
j := 6;
for y := 1 to 9 do
begin
i := 8;
for x := 1 to 9 do
begin
gotoxy(i,j);
write(t[x,y]);
i := i+3
end;
j := j+2
end;
readln;
end.
Un saludo.
Inserto el código fuente de una matriz que no debe repetir los numeros (0 al 9) ni en las lineas verticales ni en la horizontales. Como podeis ver, las 5 últimas sentencias de REPETICION están desactivadas, pues de estar todas activadas no se produce la matriz o rara vez se produce, y ese es my problema, desdeluego, no faltaba mas. Agradezco infinitamente la ayuda que me puedan prestar:
program Sin_repeticion_en_vectores;
uses crt;
type
digitos = set of 0..9;
var
t : array[1..9,1..9] of integer;
x,y,i,j,n,p,q,gd,gm : integer;
a,b,c,d,e,f,g,h,k,l : digitos;
begin
randomize;
a := [];
b := [];
c := [];
d := [];
e := [];
f := [];
g := [];
h := [];
k := [];
l := [];
for y := 1 to 9 do
begin
repeat
t[1,y] := random(10);
n := t[1,y]
until ((n in h)=false) and ((n in a)=false);
include(h,n); include(a,n);
repeat
t[2,y] := random(10);
n := t[2,y]
until ((n in h)=false) and ((n in b)=false);
include(h,n); include(b,n);
repeat
t[3,y] := random(10);
n := t[3,y]
until ((n in h)=false) and ((n in c)=false);
include(h,n); include(c,n);
repeat
t[4,y] := random(10);
n := t[4,y]
until ((n in h) = false) and ((n in d) = false);
include(h,n); include(d,n);
{repeat
t[5,y] := random(10);
n := t[5,y]
until ((n in h) = false) and ((n in e) = false);
include(h,n); include(e,n);
repeat
t[6,y] := random(10);
n := t[6,y]
until ((n in h) = false) and ((n in f) = false);
include(h,n); include(f,n);
repeat
t[7,y] := random(10);
n := t[7,y]
until ((n in h) = false) and ((n in g) = false);
include(h,n); include(g,n);
repeat
t[8,y] := random(10);
n := t[8,y]
until ((n in h) = false) and ((n in k) = false);
include(h,n); include(k,n);
repeat
t[9,y] := random(10);
n := t[9,y]
until ((n in h) = false) and ((n in l) = false);
include(l,n);}
h := []
end;
j := 6;
for y := 1 to 9 do
begin
i := 8;
for x := 1 to 9 do
begin
gotoxy(i,j);
write(t[x,y]);
i := i+3
end;
j := j+2
end;
readln;
end.
Un saludo.
Valora esta pregunta


0