Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program myspiral;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const
- Matrix: array [0..4, 0..4] of Integer = (
- (1, 2, 3, 4, 5),
- (16, 17, 18, 19, 6),
- (15, 24, 25, 20, 7),
- (14, 23, 22, 21, 8),
- (13, 12, 11, 10, 9)
- );
- {
- Matrix: array [0..3, 0..3] of Integer = (
- (1, 2, 3, 4),
- (12, 13, 14, 5),
- (11, 16, 15, 6),
- (10, 9, 8, 7)
- );
- }
- var
- i, j, Index, WallI, WallJ, Turns, Len, Width, Height: Integer;
- begin
- Writeln('Show must go on!');
- for i := 0 to High(Matrix) do
- begin
- for j := 0 to High(Matrix) do
- Write(Matrix[i, j], ' ');
- Writeln;
- end;
- Writeln('_______________');
- Index := 1;
- Len := High(Matrix) + 1;
- Height := High(Matrix);
- Width := High(Matrix);
- i := 0;
- j := 0;
- while Index <= Len*Len do
- begin
- while j < Width do
- begin
- Write(Matrix[i, j], ' ');
- Inc(Index);
- Inc(j);
- end;
- {
- Writeln;
- Writeln('Current values [', i, ', ', j, ']', ', height = ', Height);
- }
- while i < Height do
- begin
- Write(Matrix[i, j], ' ');
- Inc(Index);
- Inc(i);
- end;
- {
- Writeln;
- Writeln('Current values [', i, ', ', j, ']', ', width = ', Width);
- }
- while j > Len - Width - 1 do begin
- Write(Matrix[i, j], ' ');
- Inc(Index);
- Dec(j);
- end;
- Dec(Height);
- {
- Writeln;
- Writeln('Current values [', i, ', ', j, ']', ', height = ', Height);
- }
- while i > Len - Height - 1 do begin
- Write(Matrix[i, j], ' ');
- Inc(Index);
- Dec(i);
- end;
- Dec(Width);
- {
- Writeln;
- Writeln('Current values [', i, ', ', j, ']', ', width = ', Width);
- }
- if Index = Len*Len then begin
- Writeln(Matrix[i, j]);
- Inc(Index);
- end;
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement