-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirections_reduction.pas
More file actions
54 lines (48 loc) · 1.2 KB
/
directions_reduction.pas
File metadata and controls
54 lines (48 loc) · 1.2 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
{
5 kyu
Directions Reduction
https://www.codewars.com/kata/550f22f4d758534c1100025a
}
program directions_reduction;
{$mode objfpc}{$H+}
uses
SysUtils,
StrUtils,
directions_reduction_unit;
function ArrayToString(A: TStringArray): string;
var
i: int64;
res: string;
begin
res := '[';
for i := 0 to High(A) do
res += A[i] + ', ';
if (res = '[') then
Result := '[]'
else
Result := Copy(res, 1, Length(res) - 2) + ']';
end;
procedure DoTest(plan: TStringArray; Expected: string);
var
Actual: string;
begin
Actual := ArrayToString(DirReduc(plan));
writeln('Plan : ', ArrayToString(plan));
writeln('Expected: ', Expected);
writeln('Actual : ', Actual);
if Expected = Actual then
writeln('-> OK', LineEnding)
else
writeln('-> FAIL', LineEnding);
end;
begin
DoTest(['NORTH', 'SOUTH', 'SOUTH', 'EAST', 'WEST', 'NORTH', 'WEST'],
'[WEST]');
DoTest(['EAST', 'EAST', 'WEST', 'NORTH', 'WEST', 'EAST', 'EAST',
'SOUTH', 'NORTH', 'WEST'],
'[EAST, NORTH]');
DoTest(['NORTH', 'SOUTH', 'SOUTH', 'EAST', 'WEST', 'NORTH'],
'[]');
DoTest(['WEST', 'EAST', 'SOUTH', 'EAST', 'WEST', 'WEST'],
'[SOUTH, WEST]');
end.