Advertisement
Janilabo

erm

Dec 18th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.53 KB | None | 0 0
  1. {$loadlib pumbaa.dll}
  2.  
  3. function GatherTIA(arr: TIntegerArray; counts: TIntegerArray): T2DIntegerArray;
  4. var
  5.   a, d, h, i, j, l, t, m, x, y, z: Integer;
  6. begin
  7.   SetLength(Result, 0);
  8.   l := High(counts);
  9.   SetLength(Result, (l + 1));
  10.   if (l > 0) then
  11.   begin
  12.     j := 0;
  13.     h := High(arr);
  14.     if (h > -1) then
  15.     for i := 0 to l do
  16.     begin
  17.       y := counts[i];
  18.       if (counts[i] <> 0) then
  19.       begin
  20.         a := Abs(counts[i]);
  21.         if (counts[i] < 0) then
  22.           d := Abs((j - 1) - 0)
  23.         else
  24.           d := Abs((j - 1) - h);
  25.         if (a < d) then
  26.           z := a
  27.         else
  28.           z := d;
  29.         if (z > 0) then
  30.         begin
  31.           SetLength(Result[i], z);
  32.           if (counts[i] < 0) then
  33.             m := 0
  34.           else
  35.             m := 1;
  36.           case m of
  37.             0:
  38.             begin
  39.               t := (j - 2);
  40.               j := ((t - z) + 1);
  41.               for x := t downto j do
  42.                 Result[i][(t - x)] := arr[x];
  43.               j := (j + 1);
  44.             end;
  45.             1:
  46.             begin
  47.               t := j;
  48.               j := ((j + z) - 1);
  49.               for x := t to j do
  50.                 Result[i][(x - t)] := arr[x];
  51.               j := (j + 1);
  52.             end;
  53.           end;
  54.         end;
  55.       end;
  56.     end;
  57.   end;
  58. end;
  59.  
  60. function TestSplit(x: Integer; divisions: Integer): TIntegerArray;
  61. var
  62.   h, i, d, s, o, n: Integer;
  63.   r: TIntegerArray;
  64. begin
  65.   if (x > 0) then
  66.   begin
  67.     SetLength(Result, 1);
  68.     Result[0] := x;
  69.     if (divisions < 0) then
  70.       divisions := x;
  71.     if (divisions > 0) then
  72.     begin
  73.       d := 0;
  74.       h := 0;
  75.       o := 0;
  76.       n := 0;
  77.       repeat
  78.         r := pp_Clone(Result);
  79.         s := 0;
  80.         SetLength(Result, ((h + 1) * 2));
  81.         for i := 0 to h do
  82.         begin
  83.           if (r[i] > 1) then
  84.           begin
  85.             Result[(s + 1)] := (r[i] div 2);
  86.             Result[s] := (r[i] - Result[(s + 1)]);
  87.             s := (s + 2);
  88.           end else
  89.           begin
  90.             Result[s] := r[i];
  91.             s := (s + 1);
  92.           end;
  93.         end;
  94.         h := (s - 1);
  95.         SetLength(Result, s);
  96.         SetLength(r, 0);
  97.         d := (d + 1);
  98.       until not ((s < x) and (d < divisions));
  99.     end;
  100.   end else
  101.     SetLength(Result, 0);
  102. end;
  103.  
  104. var
  105.   t, g: TIntegerArray;
  106.   a: T2DIntegerArray;
  107.  
  108. begin
  109.   ClearDebug;
  110.   t := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  111.   g := [3, -25, 111, -255, 242, 225, -255];
  112.   a := GatherTIA(t, g);
  113.   WriteLn(pp_ToStr(a));
  114. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement