Look-and-say sequence: Difference between revisions

Line 4,526:
return o
</syntaxhighlight>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! Code
! Comments
|-
|
≪ DUP 1 DUP SUB → str char
≪ 2 '''WHILE''' str OVER DUP SUB char == '''REPEAT''' 1 + '''END'''
DUP 1 - →STR char +
str ROT OVER SIZE SUB
≫ ≫ 'CountCut' STO
"" 1 CF SWAP
'''WHILE''' 1 FC? '''REPEAT'''
CountCut '''IF''' DUP "" == '''THEN''' 1 SF '''END'''
ROT ROT + SWAP
'''END''' DROP
≫ 'LKSAY' STO
|
''( "####" -- "n#" "remainder" )''
Count occurences of 1st char
Build "n#"
Extract remaining string
''("M(n)" -- "M(n+1)" )''
Initialize M(n+1) and flag
set flag if at end of "M(n)"
build "M(n+1)"
Forget "M(n)"
|}
The following line of code delivers what is required:
≪ {} 1 "1" 12 START SWAP OVER + SWAP LKSAY NEXT DROP ≫
{{out}}
<pre>
1: { "1" "11" "21" "1211" "111221" "312211" "13112221" "1113213211" "31131211131221" "13211311123113112211" "11131221133112132113212221" "3113112221232112111312211312113211" }
</pre>
 
=={{header|Ruby}}==
1,150

edits