-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_the_smallest.pas
More file actions
58 lines (51 loc) · 1.23 KB
/
find_the_smallest.pas
File metadata and controls
58 lines (51 loc) · 1.23 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
{
5 kyu
Find the smallest
https://www.codewars.com/kata/573992c724fc289553000e95
}
program find_the_smallest;
{$mode objfpc}{$H+}
uses
find_the_smallest_unit,
SysUtils;
type
TSmallest = array [0..2] of int64;
function ArrayToString(A: TSmallest): 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(n: int64; ExpectedStr: string);
var
Actual: TSmallest;
ActualStr: string;
begin
Actual := Smallest(n);
ActualStr := ArrayToString(Actual);
writeln('n : ', n);
writeln('Expected: ', ExpectedStr);
writeln('Actual : ', ActualStr);
if ExpectedStr = ActualStr then
writeln('-> OK', LineEnding)
else
writeln('-> FAIL', LineEnding);
end;
begin
DoTest(261235, '[126235, 2, 0]');
DoTest(22, '[22, 0, 0]');
DoTest(209917, '[29917, 0, 1]');
DoTest(285365, '[238565, 3, 1]');
DoTest(269045, '[26945, 3, 0]');
DoTest(296837, '[239687, 4, 1]');
DoTest(1000000, '[1, 0, 6]');
DoTest(345657, '[345567, 3, 4]');
DoTest(96682790625023136, '[9668279062523136, 11, 0]');
end.