Look-and-say sequence: Difference between revisions
Content deleted Content added
Added solution for Action! |
Not a robot (talk | contribs) Add CLU |
||
Line 1,074: | Line 1,074: | ||
<lang clojure>user> (take 8 (iterate look-and-say 1)) |
<lang clojure>user> (take 8 (iterate look-and-say 1)) |
||
(1 11 21 1211 111221 312211 13112221 1113213211)</lang> |
(1 11 21 1211 111221 312211 13112221 1113213211)</lang> |
||
=={{header|CLU}}== |
|||
<lang clu>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</lang> |
|||
{{out}} |
|||
<pre>1 |
|||
11 |
|||
21 |
|||
1211 |
|||
111221 |
|||
312211 |
|||
13112221 |
|||
1113213211 |
|||
31131211131221 |
|||
13211311123113112211 |
|||
11131221133112132113212221 |
|||
3113112221232112111312211312113211 |
|||
1321132132111213122112311311222113111221131221 |
|||
11131221131211131231121113112221121321132132211331222113112211 |
|||
311311222113111231131112132112311321322112111312211312111322212311322113212221</pre> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |