-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbest_travel.pas
More file actions
62 lines (54 loc) · 1.28 KB
/
best_travel.pas
File metadata and controls
62 lines (54 loc) · 1.28 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
54
55
56
57
58
59
60
61
62
{
5 kyu
Best travel
https://www.codewars.com/kata/55e7280b40e1c4a06d0000aa
}
program best_travel;
{$mode objfpc}{$H+}
uses
SysUtils,
best_travel_unit;
type
TInt64Array = array of int64;
var
ts: TInt64Array;
function ArrayToString(A: TInt64Array): string;
var
i: int64;
begin
Result := '[';
for i := 0 to High(A) do
begin
Result += IntToStr(A[i]) + ', ';
end;
Result := Copy(Result, 1, Length(Result) - 2) + ']';
end;
procedure DoTest(t, k: int64; ls: TInt64Array; Expected: int64);
var
Actual: int64;
begin
Actual := ChooseBestSum(t, k, ls);
writeln('Max. Miles t : ', t);
writeln('Number Towns k: ', k);
writeln('Distances ls : (', Length(ls), ') = ', ArrayToString(ls));
writeln('Expected : ', Expected);
writeln('Actual : ', Actual);
if Expected = Actual then
writeln('-> OK', LineEnding)
else
writeln('-> FAIL', LineEnding);
end;
begin
ts := [50, 55, 57, 58, 60];
DoTest(174, 3, ts, 173);
ts := [50, 55, 56, 57, 58];
DoTest(163, 3, ts, 163);
ts := [50];
DoTest(163, 3, ts, -1);
ts := [91, 74, 73, 85, 73, 81, 87];
DoTest(230, 3, ts, 228);
DoTest(331, 2, ts, 178);
DoTest(331, 4, ts, 331);
ts := [91, 74, 73, 85, 73, 81, 87];
DoTest(331, 5, ts, -1);
end.