RosettaCodeData/Task/Look-and-say-sequence/Pascal/look-and-say-sequence-1.pascal
2015-02-20 00:35:01 -05:00

39 lines
707 B
Text

program LookAndSayDemo(input, output);
uses
SysUtils;
function LookAndSay (s: string): string;
var
item: char;
index: integer;
count: integer;
begin
LookAndSay := '';
item := s[1];
count := 1;
for index:= 2 to length(s) do
if item = s[index] then
inc(count)
else
begin
LookAndSay := LookAndSay + intTostr(count) + item;
item := s[index];
count := 1;
end;
LookAndSay := LookAndSay + intTostr(count) + item;
end;
var
number: string;
begin
writeln('Press RETURN to continue and ^C to stop.');
number := '1';
while not eof(input) do
begin
write(number);
readln;
number := LookAndSay(number);
end;
end.