-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuddy_pairs.pas
More file actions
53 lines (46 loc) · 1.06 KB
/
buddy_pairs.pas
File metadata and controls
53 lines (46 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
5 kyu
Buddy Pairs
https://www.codewars.com/kata/59ccf051dcc4050f7800008f
}
program buddy_pairs;
{$mode objfpc}{$H+}
uses
buddy_pairs_unit,
SysUtils;
type
TBuddy = array [0..1] of int64;
function ArrayToString(A: TBuddy): string;
var
i: int64;
res: string;
begin
res := '[';
for i := 0 to High(A) do
res += IntToStr(A[i]) + ', ';
if (res = '[') then
Result := '[]'
else
Result := Copy(res, 1, Length(res) - 2) + ']';
end;
procedure DoTest(Expected: string; start, limit: int64);
var
Actual: string;
begin
Actual := ArrayToString(Buddy(start, limit));
writeln('Start : ', start);
writeln('Limit : ', limit);
writeln('Expected: ', Expected);
writeln('Actual : ', Actual);
if Expected = Actual then
writeln('-> OK', LineEnding)
else
writeln('-> FAIL', LineEnding);
end;
begin
DoTest('[48, 75]', 10, 50);
DoTest('[-1, -1]', 200, 1000);
DoTest('[62744, 75495]', 57345, 90061);
DoTest('[-1, -1]', 2177, 4357);
DoTest('[1081184, 1331967]', 1071625, 1103735);
end.