green1ant

spiral

Dec 10th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.96 KB | None | 0 0
  1. program myspiral;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. const
  9.  
  10.    Matrix: array [0..4, 0..4] of Integer = (
  11.       (1,  2,  3,  4,  5),
  12.       (16, 17, 18, 19, 6),
  13.       (15, 24, 25, 20, 7),
  14.       (14, 23, 22, 21, 8),
  15.       (13, 12, 11, 10, 9)
  16.    );
  17.  {
  18.    Matrix: array [0..3, 0..3] of Integer = (
  19.       (1,  2,  3,  4),
  20.       (12, 13, 14, 5),
  21.       (11, 16, 15, 6),
  22.       (10, 9, 8, 7)
  23.    );
  24.    }
  25. var
  26.    i, j, Index, WallI, WallJ, Turns, Len, Width, Height: Integer;
  27. begin
  28.    Writeln('Show must go on!');
  29.  
  30.    for i := 0 to High(Matrix) do
  31.    begin
  32.       for j := 0 to High(Matrix) do
  33.          Write(Matrix[i, j], ' ');
  34.       Writeln;
  35.    end;
  36.  
  37.    Writeln('_______________');
  38.  
  39.    Index := 1;
  40.    Len := High(Matrix) + 1;
  41.  
  42.    Height := High(Matrix);
  43.    Width := High(Matrix);
  44.    i := 0;
  45.    j := 0;
  46.    while Index <= Len*Len do
  47.    begin
  48.       while j < Width do
  49.       begin
  50.          Write(Matrix[i, j], ' ');
  51.          Inc(Index);
  52.          Inc(j);
  53.       end;
  54.       {
  55.       Writeln;
  56.       Writeln('Current values [', i, ', ', j, ']', ', height = ', Height);
  57.       }
  58.       while i < Height do
  59.       begin
  60.          Write(Matrix[i, j], ' ');
  61.          Inc(Index);
  62.          Inc(i);
  63.       end;
  64.       {
  65.       Writeln;
  66.       Writeln('Current values [', i, ', ', j, ']', ', width = ', Width);
  67.       }
  68.       while j > Len - Width - 1 do begin
  69.           Write(Matrix[i, j], ' ');
  70.           Inc(Index);
  71.           Dec(j);
  72.       end;
  73.       Dec(Height);
  74.       {
  75.       Writeln;
  76.       Writeln('Current values [', i, ', ', j, ']', ', height = ', Height);
  77.       }
  78.       while i > Len - Height - 1 do begin
  79.           Write(Matrix[i, j], ' ');
  80.           Inc(Index);
  81.           Dec(i);
  82.       end;
  83.       Dec(Width);
  84.       {
  85.       Writeln;
  86.       Writeln('Current values [', i, ', ', j, ']', ', width = ', Width);
  87.       }
  88.       if Index = Len*Len then begin
  89.          Writeln(Matrix[i, j]);
  90.          Inc(Index);
  91.       end;
  92.    end;
  93.  
  94.    Readln;
  95. end.
Add Comment
Please, Sign In to add comment