-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world_unit.pas
More file actions
58 lines (48 loc) · 984 Bytes
/
hello_world_unit.pas
File metadata and controls
58 lines (48 loc) · 984 Bytes
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
{
8 kyu
Function 1 - hello world
https://www.codewars.com/kata/523b4ff7adca849afe000035
}
unit hello_world_unit;
{$mode objfpc}{$H+}
interface
function Greet(): string;
implementation
uses
SysUtils,
Generics.Collections,
Generics.Defaults;
type
TIntList = specialize TList<integer>;
TIntComparer = specialize TComparer<integer>;
function CompareInt(constref L, R: integer): integer;
begin
if L < R then
Result := -1
else if L > R then
Result := 1
else
Result := 0;
end;
function Greet(): string;
const
Data = '560329710022101891149903341108911083410867119111044511187111';
k = 5;
m = 1000;
var
list: TIntList;
i: integer = 1;
begin
list := TIntList.Create;
while i < Length(Data) do
begin
list.Add(StrToInt(Copy(Data, i, k)));
i := i + k;
end;
list.Sort(TIntComparer.Construct(@CompareInt));
Result := '????????????';
for i := 0 to list.Count - 1 do
Result[i + 1] := Chr(list[i] mod m);
list.Free;
end;
end.