22 lines
484 B
Plaintext
22 lines
484 B
Plaintext
function lookAndSay S
|
|
put 0 into C
|
|
put char 1 of S into lastChar
|
|
repeat with i = 2 to length(S)
|
|
add 1 to C
|
|
if char i of S is lastChar then next repeat
|
|
put C & lastChar after R
|
|
put 0 into C
|
|
put char i of S into lastChar
|
|
end repeat
|
|
return R & C + 1 & lastChar
|
|
end lookAndSay
|
|
|
|
on demoLookAndSay
|
|
put 1 into x
|
|
repeat 10
|
|
put x & cr after message
|
|
put lookAndSay(x) into x
|
|
end repeat
|
|
put x after message
|
|
end demoLookAndSay
|