Look-and-say sequence: Difference between revisions

Add ABC
(add SETL)
(Add ABC)
 
(4 intermediate revisions by 3 users not shown)
Line 221:
newline: db 13,10,'$' ; Newline to print in between members
memb: db '1$' ; This is where the current member is stored</syntaxhighlight>
 
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN look.and.say seq:
PUT "" IN result
PUT 0 IN n
PUT "" IN c
FOR ch IN seq:
SELECT:
c=ch:
PUT n+1 IN n
ELSE:
IF n>0: PUT result^"`n`"^c IN result
PUT 1 IN n
PUT ch IN c
RETURN result^"`n`"^c
 
PUT "1" IN item
 
FOR i IN {1..14}:
WRITE item/
PUT look.and.say item IN item</syntaxhighlight>
{{out}}
<pre>1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
3113112221232112111312211312113211
1321132132111213122112311311222113111221131221
11131221131211131231121113112221121321132132211331222113112211</pre>
 
 
Line 1,870 ⟶ 1,907:
number := lookAndSayNext(number)
}</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
proc lookandsay . a$ .
c = 1
p$ = substr a$ 1 1
for i = 2 to len a$
if p$ = substr a$ i 1
c += 1
else
s$ &= c & p$
p$ = substr a$ i 1
c = 1
.
.
s$ &= c & p$
swap a$ s$
.
b$ = 1
print b$
for k = 1 to 10
lookandsay b$
print b$
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 4,706 ⟶ 4,769:
return ! || $ /*return the ! string plus the $ string*/</syntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version &nbsp; (the simple version).}}<br><br>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Sequence 10 1>>;
};
 
Sequence {
0 e.seq = ;
s.N e.seq = <Prout e.seq>
<Sequence <- s.N 1> <LookSay e.seq>>;
}
 
LookSay {
= ;
e.1,
<First <Group e.1> e.1>: (e.group) e.rest,
<Lenw e.group>: s.num s.item e.discard =
s.num s.item <LookSay e.rest>;
}
 
Group {
s.1 s.1 e.rest = <+ 1 <Group s.1 e.rest>>;
s.1 e.rest = 1;
};</syntaxhighlight>
{{out}}
<pre>1
1 1
2 1
1 2 1 1
1 1 1 2 2 1
3 1 2 2 1 1
1 3 1 1 2 2 2 1
1 1 1 3 2 1 3 2 1 1
3 1 1 3 1 2 1 1 1 3 1 2 2 1
1 3 2 1 1 3 1 1 1 2 3 1 1 3 1 1 2 2 1 1</pre>
 
=={{header|Ring}}==
Line 5,760 ⟶ 5,858:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">var lookAndSay = Fn.new { |s|
var res = ""
var digit = s[0]
2,094

edits