Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$loadlib pumbaa.dll}
- function GatherTIA(arr: TIntegerArray; counts: TIntegerArray): T2DIntegerArray;
- var
- a, d, h, i, j, l, t, m, x, y, z: Integer;
- begin
- SetLength(Result, 0);
- l := High(counts);
- SetLength(Result, (l + 1));
- if (l > 0) then
- begin
- j := 0;
- h := High(arr);
- if (h > -1) then
- for i := 0 to l do
- begin
- y := counts[i];
- if (counts[i] <> 0) then
- begin
- a := Abs(counts[i]);
- if (counts[i] < 0) then
- d := Abs((j - 1) - 0)
- else
- d := Abs((j - 1) - h);
- if (a < d) then
- z := a
- else
- z := d;
- if (z > 0) then
- begin
- SetLength(Result[i], z);
- if (counts[i] < 0) then
- m := 0
- else
- m := 1;
- case m of
- 0:
- begin
- t := (j - 2);
- j := ((t - z) + 1);
- for x := t downto j do
- Result[i][(t - x)] := arr[x];
- j := (j + 1);
- end;
- 1:
- begin
- t := j;
- j := ((j + z) - 1);
- for x := t to j do
- Result[i][(x - t)] := arr[x];
- j := (j + 1);
- end;
- end;
- end;
- end;
- end;
- end;
- end;
- function TestSplit(x: Integer; divisions: Integer): TIntegerArray;
- var
- h, i, d, s, o, n: Integer;
- r: TIntegerArray;
- begin
- if (x > 0) then
- begin
- SetLength(Result, 1);
- Result[0] := x;
- if (divisions < 0) then
- divisions := x;
- if (divisions > 0) then
- begin
- d := 0;
- h := 0;
- o := 0;
- n := 0;
- repeat
- r := pp_Clone(Result);
- s := 0;
- SetLength(Result, ((h + 1) * 2));
- for i := 0 to h do
- begin
- if (r[i] > 1) then
- begin
- Result[(s + 1)] := (r[i] div 2);
- Result[s] := (r[i] - Result[(s + 1)]);
- s := (s + 2);
- end else
- begin
- Result[s] := r[i];
- s := (s + 1);
- end;
- end;
- h := (s - 1);
- SetLength(Result, s);
- SetLength(r, 0);
- d := (d + 1);
- until not ((s < x) and (d < divisions));
- end;
- end else
- SetLength(Result, 0);
- end;
- var
- t, g: TIntegerArray;
- a: T2DIntegerArray;
- begin
- ClearDebug;
- t := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
- g := [3, -25, 111, -255, 242, 225, -255];
- a := GatherTIA(t, g);
- WriteLn(pp_ToStr(a));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement