Tagged: programming

Logo program which generates the look and say sequence

[In the program below the ” is inserted in the text in WordPress in order to prevent the 😮  emoticon (generated by “colono”) from being inserted. Please remove the ” before running the program in your Logo interpreter.]

to look.and.say.loop :in :run :c :out
if empty? :in [output (word :out :run :c)]
if equal? first :in :c [output look.and.say.loop bf :in :run+1 :c :out]
output look.and.say.loop bf :in 1 first :in (word :out :run :c)
end
to look.and.say :in
if empty? :in [output :in]
output look.and.say.loop bf :in 1 first :in “||
end

show cascade 10 [print ? look.and.say ?] 1

Output:

1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
Found at http://rosettacode.org/wiki/Look-and-say_sequence#Logo