Simba Code:
program New;
function T3DIntArrToString(Arr: T3DIntegerArray): string;
var
i, ii, iii, H, HH, HHH: integer;
begin
H := High(Arr);
for i := 0 to H do
begin
Result := Result + '(';
HH := High(Arr[i]);
for ii := 0 to HH do
begin
Result := Result + '[';
HHH := High(Arr[i][ii]);
for iii := 0 to HHH do
Result := Result + IntToStr(Arr[i][ii][iii])+'#';
Result := Result + ']';
end;
Result := Result + ')';
end;
end;
function StringToIntArr(s: string): TIntegerArray;
var
a, L, LL: integer;
tmp: string;
begin
L := Length(s);
for a := 1 to L do
begin
if s[a] <> '#' then
tmp := tmp + s[a]
else
begin
LL := Length(Result);
SetLength(Result, LL + 1);
Result[LL] := StrToInt(GetNumbers(tmp));
tmp := '';
end;
end;
end;
function StringTo2DIntArr(s: string): T2DIntegerArray;
var
a, L, LS, LE: integer;
StartBrackets, EndBrackets: TIntegerArray;
tmp: string;
begin
L := Length(s);
for a := 1 to L do
if s[a] = '[' then
begin
LS := Length(StartBrackets);
SetLength(StartBrackets, LS + 1);
StartBrackets[LS] := a;
end else if s[a] = ']' then
begin
LE := Length(EndBrackets);
SetLength(EndBrackets, LE + 1);
EndBrackets[LE] := a;
end;
SetLength(Result, Length(StartBrackets));
L := High(Result);
for a := 0 to L do
Result[a] := StringToIntArr(Copy(s, StartBrackets[a], EndBrackets[a]-StartBrackets[a]));
end;
function iCopy(s: string; iStart, iEnd: integer): string;
var
i: integer;
begin
for i := iStart to iEnd do
Result := Result + s[i];
end;
function StringTo3DIntArr(s: string): T3DIntegerArray;
var
a, L, LS, LE: integer;
StartBrackets, EndBrackets: TIntegerArray;
tmp: string;
begin
L := Length(s);
for a := 1 to L do
if s[a] = '(' then
begin
LS := Length(StartBrackets);
SetLength(StartBrackets, LS + 1);
StartBrackets[LS] := a;
end else if s[a] = ')' then
begin
LE := Length(EndBrackets);
SetLength(EndBrackets, LE + 1);
EndBrackets[LE] := a;
end;
SetLength(Result, Length(StartBrackets));
L := High(Result);
for a := 0 to L do
Result[a] := StringTo2DIntArr(iCopy(s, StartBrackets[a], EndBrackets[a]));
end;
var
tia: t3dintegerarray;
s: string;
begin
SetLength(tia, RandomRange(3, 5));
for i := 0 to high(tia) do
begin
SetLength(tia[i], RandomRange(3, 5));
for ii := 0 to high(tia[i]) do
begin
SetLength(tia[i][ii], RandomRange(3, 5));
for iii := 0 to high(tia[i][ii]) do
tia[i][ii][iii] := RandomRange(0, 9);
end;
end;
s := t3dintarrtostring(tia);
writeln(s);
tia := StringTo3DIntArr(s);
s := t3dintarrtostring(tia);
writeln(s);
end.
I want to turn a 3d integer array into a string and vice versa, but the StringTo3DIntArr seems to mess up something.
Above I first create a 3d int array, then turn it into a string and print it. That's just fine. But when I try to turn it back to a T3DIntegerArray and to a string again, the output is not the same anymore.
Simba Code:
([4#3#4#][2#5#0#][4#8#6#][4#8#5#1#])([7#3#8#1#][5#7#3#8#][1#1#1#1#])([0#2#3#][2#1#0#][5#1#4#][8#6#8#2#])([6#7#0#3#][6#2#5#][1#6#4#][1#2#4#])
([4#3#4#][2#5#0#][4#8#6#][4#8#5#1#])([7#3#8#1#][5#7#3#8#][1#1#1#1#])([0#2#3#][2#1#0#][5#1#4#][8#6#8#2#])([6#7#0#3#][6#2#5#][1#6#4#][1#2#4#])([4#3#4#][2#5#0#][4#8#6#][4#8#5#1#])([7#3#8#1#][5#7#3#8#][1#1#1#1#])([0#2#3#][2#1#0#][5#1#4#][8#6#8#2#])([6#7#0#3#][6#2#5#][1#6#4#][1#2#4#])
As you can see, somewhere the array is doubled.
Where? I can't find it!!