Well, yes, as usual hype, but sometimes it's funny.
For example, how would you solve such a problem?
...
Okay, then I'll try to answer my question myself.
A fairly typical Pascal code for solving this problem might look like this:
procedure TForm1.Button1Click(Sender: TObject);
var
Words: TStringArray;
Palindromes: TStringList;
I: Integer;
s: string;
begin
Words := Memo1.Lines.Text.Split([#9, #10, #13, ' ', ',', ';'], TStringSplitOptions.ExcludeEmpty);
for I := 0 to High(Words) do
Words[I] := LowerCase(Words[I]);
Palindromes := TStringList.Create;
try
for I := 0 to High(Words) do
if (Words[I].Length > 2) and (Words[I] = ReverseString(Words[I])) then
Palindromes.Add(Words[I]);
if Palindromes.Count <> 0 then
begin
Palindromes.Sort;
I := 0;
while I < Palindromes.Count do
begin
s := Palindromes[I];
Memo1.Append(s);
repeat
Inc(I);
until (I >= Palindromes.Count) or (Palindromes[I] <> s);
end;
end
else
Memo1.Append('no palindromes');
finally
Palindromes.Free;
end;
end;
But it could also look like this:
procedure TForm1.Button1Click(Sender: TObject);
function ToLower(const s: string): string; begin ToLower := LowerCase(s) end;
function Fits(const s: string): Boolean; begin Fits := (s.Length > 2) and (s = ReverseString(s)) end;
function Less(const L, R: string): Boolean; begin Less := L < R end;
function Join(const L, R: string): string; begin Join := R + LineEnding + L end;
begin
Memo1.Append(Memo1.Lines.Text
.Words([#9, #10, #13, ' ', ',', ';'])
.Map(@ToLower)
.Select(@Fits)
.Distinct(@Less)
.Fold(@Join)
.OrElse('no palindromes')
);
end;
And, of course, everyone can have their own opinion, which of the solutions is more readable and simpler.