-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsecutive_strings.pas
More file actions
57 lines (50 loc) · 1.33 KB
/
consecutive_strings.pas
File metadata and controls
57 lines (50 loc) · 1.33 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
{
6 kyu
Consecutive strings
https://www.codewars.com/kata/56a5d994ac971f1ac500003e
}
program consecutive_strings;
{$mode objfpc}{$H+}
uses
consecutive_strings_unit;
type
TStringArray = array of string;
function ArrayToString(A: TStringArray): string;
var
i: integer;
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(strarr: TStringArray; k: int64; Expected: string);
var
Actual: string;
begin
Actual := LongestConsec(strarr, k);
writeln('Strings : ', ArrayToString(strarr));
writeln('k : ', k);
writeln('Expected: ', Expected);
writeln('Actual : ', Actual);
if Expected = Actual then
writeln('-> OK', LineEnding)
else
writeln('-> FAIL', LineEnding);
end;
begin
DoTest(['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'],
2, 'orangeyellow');
DoTest(['abcd', 'efghijk', 'lmnop', 'qrst', 'uvwx', 'yzzz', 'lmnop', 'efghijk'],
3, 'abcdefghijklmnop');
DoTest(['zone', 'abigail', 'theta', 'form', 'libe', 'zas', 'theta', 'abigail'],
2, 'abigailtheta');
DoTest(['it', 'wkppv', 'ixoyx', '3452', 'zzzzzzzzzzzz'],
3, 'ixoyx3452zzzzzzzzzzzz');
DoTest([],
3, '');
end.