34 lines
814 B
Text
34 lines
814 B
Text
look_and_say = proc (s: string) returns (string)
|
|
out: array[char] := array[char]$[]
|
|
count: int := 0
|
|
last: char := '\000'
|
|
|
|
for c: char in string$chars(s) do
|
|
if c ~= last then
|
|
if count ~= 0 then
|
|
array[char]$addh(out, char$i2c(count + 48))
|
|
array[char]$addh(out, last)
|
|
end
|
|
last := c
|
|
count := 1
|
|
else
|
|
count := count + 1
|
|
end
|
|
end
|
|
|
|
array[char]$addh(out, char$i2c(count + 48))
|
|
array[char]$addh(out, last)
|
|
return (string$ac2s(out))
|
|
end look_and_say
|
|
|
|
start_up = proc ()
|
|
lines = 15
|
|
|
|
po: stream := stream$primary_output()
|
|
cur: string := "1"
|
|
|
|
for i: int in int$from_to(1, lines) do
|
|
stream$putl(po, cur)
|
|
cur := look_and_say(cur)
|
|
end
|
|
end start_up
|