Look-and-say sequence: Difference between revisions

Added solution for Action!
(Add Modula-2)
(Added solution for Action!)
Line 222:
memb: db '1$' ; This is where the current member is stored</lang>
 
 
=={{header|Action!}}==
<lang Action!>BYTE FUNC GetLength(CHAR ARRAY s BYTE pos)
CHAR c
BYTE len
 
c=s(pos)
len=1
DO
pos==+1
IF pos<=s(0) AND s(pos)=c THEN
len==+1
ELSE
EXIT
FI
OD
RETURN (len)
 
PROC Append(CHAR ARRAY text,suffix)
BYTE POINTER srcPtr,dstPtr
BYTE len
 
len=suffix(0)
IF text(0)+len>255 THEN
len=255-text(0)
FI
IF len THEN
srcPtr=suffix+1
dstPtr=text+text(0)+1
MoveBlock(dstPtr,srcPtr,len)
text(0)==+suffix(0)
FI
RETURN
 
PROC LookAndSay(CHAR ARRAY in,out)
BYTE pos,len
CHAR ARRAY tmp(5)
 
pos=1 len=0 out(0)=0
WHILE pos<=in(0)
DO
len=GetLength(in,pos)
StrB(len,tmp)
Append(out,tmp)
out(0)==+1
out(out(0))=in(pos)
pos==+len
OD
RETURN
 
PROC Main()
CHAR ARRAY s1(256),s2(256)
BYTE i
 
SCopy(s1,"1")
PrintE(s1)
FOR i=1 TO 11
DO
IF (i&1)=0 THEN
LookAndSay(s2,s1)
PrintE(s1)
ELSE
LookAndSay(s1,s2)
PrintE(s2)
FI
OD
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Look-and-say_sequence.png Screenshot from Atari 8-bit computer]
<pre>
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
3113112221232112111312211312113211
</pre>
 
=={{header|Ada}}==
Anonymous user