- Joined
- Jun 9, 2022
- Messages
- 1
- Reaction score
- 0
Good night people,
I am studying Pascal, and am i with a problem.
My code needs to make combinations of four numbers, from left to right but i want to prevent those combinations repeating the same thing being the numbers in positions, but worth the same thing from right to left.
Does anyone have any idea how to do that?
code:
program mistureba;
type placa = array [1..4] of integer;
var a4num : array [1..24] of placa; // a4num : array [1..24,1..4] of integer
linha : integer;
const MAXDIG = 4;
procedure mistura(input : placa; index : integer);
// input tem a série de digitos da placa
// index indica a posição que inicia o arranjo
var output : placa;
p, i : integer;
begin
if index=MAXDIG then
begin // mostra / insere a sequencia que está em input
//for i := 1 to MAXDIG do
//write(input);
//writeln;
a4num[linha] := input;
linha := linha + 1;
end
else
begin
output := input;
for p := index to MAXDIG do
begin
output[index] := input[p];
for i := index to p - 1 do
output[i + 1] := input;
for i := p + 1 to MAXDIG do
output := input;
mistura(output,index + 1);
end;
end;
end;
var //a4num : placa;
p, i : integer;
begin
linha := 1;
for i := 1 to MAXDIG do
readln(a4num[linha,i]);
mistura(a4num[linha],1);
// vou mostrar o conteúdo do meu conjunto de placas
for linha := 1 to 24 do
if [i,1] = [i,4] then
begin
for i := 1 to MAXDIG do
write(a4num[linha,i]);
writeln;
end
else
begin
writeln('0');
end;
if [i,2] = [i,3] then
begin
for i := 1 to MAXDIG do
write(a4num[linha,i]);
writeln;
end
else
begin
writeln('0');
end;
end.
I am studying Pascal, and am i with a problem.
My code needs to make combinations of four numbers, from left to right but i want to prevent those combinations repeating the same thing being the numbers in positions, but worth the same thing from right to left.
Does anyone have any idea how to do that?
code:
program mistureba;
type placa = array [1..4] of integer;
var a4num : array [1..24] of placa; // a4num : array [1..24,1..4] of integer
linha : integer;
const MAXDIG = 4;
procedure mistura(input : placa; index : integer);
// input tem a série de digitos da placa
// index indica a posição que inicia o arranjo
var output : placa;
p, i : integer;
begin
if index=MAXDIG then
begin // mostra / insere a sequencia que está em input
//for i := 1 to MAXDIG do
//write(input);
//writeln;
a4num[linha] := input;
linha := linha + 1;
end
else
begin
output := input;
for p := index to MAXDIG do
begin
output[index] := input[p];
for i := index to p - 1 do
output[i + 1] := input;
for i := p + 1 to MAXDIG do
output := input;
mistura(output,index + 1);
end;
end;
end;
var //a4num : placa;
p, i : integer;
begin
linha := 1;
for i := 1 to MAXDIG do
readln(a4num[linha,i]);
mistura(a4num[linha],1);
// vou mostrar o conteúdo do meu conjunto de placas
for linha := 1 to 24 do
if [i,1] = [i,4] then
begin
for i := 1 to MAXDIG do
write(a4num[linha,i]);
writeln;
end
else
begin
writeln('0');
end;
if [i,2] = [i,3] then
begin
for i := 1 to MAXDIG do
write(a4num[linha,i]);
writeln;
end
else
begin
writeln('0');
end;
end.