# How to do a slug?

I have another question(it's hard to explain but I'll try).
With 2d array I need to do this:

for i:=1 to n do
begin
writeln;
for j:=1 to n do write(' ',a[i,j]);
end;
if the answer fo thet will be 11 22 33 44 55
66 77 88 99 12
13 14 15 16 17
18 19 20 21 22
23 24 25 26 27
Then I need that the answer would look like this:

11 22 33 44 55 12 17 22 27 26 25 24 23 18 13 66 77 88 99 16 21 20 19 14 15

Hope you understood my question

• [b][red]This message was edited by SHO1 at 2002-10-2 8:51:23[/red][/b][hr]
Oops havn't wrote the question right what I ment is is:

for i:=1 to n do
begin
writeln;
for j:=1 to n do write(' ',a[i,j]);
end;
{if the output for thet will be that:
11 22 33 44 55
66 77 88 99 12
13 14 15 16 17
18 19 20 21 22
23 24 25 26 27
Then I need another output that would look like this:

11 22 33 44 55 12 17 22 27 26 25 24 23 18 13 66 77 88 99 16 21 20 19 14 15
Thanks for trying to understand my english
Ran}

• [b][red]This message was edited by iby at 2002-10-2 18:53:26[/red][/b][hr]
: [b][red]This message was edited by SHO1 at 2002-10-2 8:51:23[/red][/b][hr]
: Oops havn't wrote the question right what I ment is is:
:
: for i:=1 to n do
: begin
: writeln;
: for j:=1 to n do write(' ',a[i,j]);
: end;
: {if the output for thet will be that:
: 11 22 33 44 55
: 66 77 88 99 12
: 13 14 15 16 17
: 18 19 20 21 22
: 23 24 25 26 27
: Then I need another output that would look like this:
:
: 11 22 33 44 55 12 17 22 27 26 25 24 23 18 13 66 77 88 99 16 21 20 19 14 15
: Thanks for trying to understand my english
: Ran}
:
:
:
:

[code][/code]

Well there are several ways to do it. None of them is really simple
(or I didn't find one). The simplest way of course is to use
a lookup table. If the array size grows, this is less and less
atractive approach. Here is one fairly simple (or at least

[code]
type my_arr=array[1..50, 1..50] of integer;

var i,j,n,limit:integer;
q:my_arr;

{ put some numbers into array so it's easier to follow the numbers }
procedure fill_array;
begin
for i:=1 to limit do
for j:= 1 to limit do
q[i,j]:=i*10+j;
end;

{ display array in standard 2D layout }
procedure display_array;
begin
writeln('This is the 2D square matrix size ',limit,' :');
for i:=1 to limit do
begin
writeln;
for j:=1 to limit do
if q[i,j]>99 then write(q[i,j],' ')
else write(q[i,j],' ');
end;
writeln;
writeln;
end;

procedure display_whirl;
begin
writeln('This is the ''unwrapped'' array... :');
n:=0;
i:=1;
j:=1;

while ((i<>(limit+1) div 2) and (j<>(limit+1) div 2)) or
((limit=2) and (n(limit-n); dec(j);

inc(i);

repeat
write(q[i,j],' ');
inc(i);
until i>(limit-n); dec(i);

dec(j);

repeat
write(q[i,j],' ');
dec(j);
until j=n; inc(n);
inc(j);
dec(i);
if limit=2 then exit;

repeat
write(q[i,j],' ');
dec(i);
until i=n;

inc(i);
inc(j);

end;
write(q[i,j],' ');
end;

begin
asm mov ax,3; int 16 end;

write('What size array would you like to see (1..50)? :');
writeln;
if limit>50 then begin
writeln('Size above 50 is not supprted...');
halt(1);
end;

fill_array;
display_array;
display_whirl;

writeln;writeln;
end.
[/code]

Iby

without you i was lost

: [b][red]This message was edited by iby at 2002-10-2 18:53:26[/red][/b][hr]
: : [b][red]This message was edited by SHO1 at 2002-10-2 8:51:23[/red][/b][hr]
: : Oops havn't wrote the question right what I ment is is:
: :
: : for i:=1 to n do
: : begin
: : writeln;
: : for j:=1 to n do write(' ',a[i,j]);
: : end;
: : {if the output for thet will be that:
: : 11 22 33 44 55
: : 66 77 88 99 12
: : 13 14 15 16 17
: : 18 19 20 21 22
: : 23 24 25 26 27
: : Then I need another output that would look like this:
: :
: : 11 22 33 44 55 12 17 22 27 26 25 24 23 18 13 66 77 88 99 16 21 20 19 14 15
: : Thanks for trying to understand my english
: : Ran}
: :
: :
: :
: :
:
: [code][/code]
:
: Well there are several ways to do it. None of them is really simple
: (or I didn't find one). The simplest way of course is to use
: a lookup table. If the array size grows, this is less and less
: atractive approach. Here is one fairly simple (or at least
:
: [code]
: type my_arr=array[1..50, 1..50] of integer;
:
: var i,j,n,limit:integer;
: q:my_arr;
:
:
: { put some numbers into array so it's easier to follow the numbers }
: procedure fill_array;
: begin
: for i:=1 to limit do
: for j:= 1 to limit do
: q[i,j]:=i*10+j;
: end;
:
:
: { display array in standard 2D layout }
: procedure display_array;
: begin
: writeln('This is the 2D square matrix size ',limit,' :');
: for i:=1 to limit do
: begin
: writeln;
: for j:=1 to limit do
: if q[i,j]>99 then write(q[i,j],' ')
: else write(q[i,j],' ');
: end;
: writeln;
: writeln;
: end;
:
: procedure display_whirl;
: begin
: writeln('This is the ''unwrapped'' array... :');
: n:=0;
: i:=1;
: j:=1;
:
: while ((i<>(limit+1) div 2) and (j<>(limit+1) div 2)) or
: ((limit=2) and (n(limit-n); dec(j);
:
: inc(i);
:
: repeat
: write(q[i,j],' ');
: inc(i);
: until i>(limit-n); dec(i);
:
: dec(j);
:
: repeat
: write(q[i,j],' ');
: dec(j);
: until j=n; inc(n);
: inc(j);
: dec(i);
: if limit=2 then exit;
:
: repeat
: write(q[i,j],' ');
: dec(i);
: until i=n;
:
: inc(i);
: inc(j);
:
: end;
: write(q[i,j],' ');
: end;
:
:
: begin
: asm mov ax,3; int 16 end;
:
: write('What size array would you like to see (1..50)? :');
: writeln;
: if limit>50 then begin
: writeln('Size above 50 is not supprted...');
: halt(1);
: end;
:
: fill_array;
: display_array;
: display_whirl;
:
: writeln;writeln;
: end.
: [/code]
:
:
: Iby
:
:
:
: