Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Look-and-say-sequence/CLU/look-and-say-sequence.clu
Normal file
34
Task/Look-and-say-sequence/CLU/look-and-say-sequence.clu
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue