Look-and-say sequence: Difference between revisions

Add ABC
m (→‎Insitux: improvement)
(Add ABC)
 
(10 intermediate revisions by 5 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 630 ⟶ 667:
 
=={{header|BASIC}}==
{{works with|QBasic}}
{{works with|QuickBasic}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|MSX BASIC|any}}
{{works with|Run BASIC}}
{{works with|Just BASIC}}
<syntaxhighlight lang="basic">10 DEFINT A-Z: I$="1"
20 FOR Z=1 TO 15
Line 658 ⟶ 703:
11131221131211131231121113112221121321132132211331222113112211
311311222113111231131112132112311321322112111312211312111322212311322113212221</pre>
 
==={{header|Applesoft BASIC}}===
{{trans|BASIC}}
<syntaxhighlight lang="vb">10 I$="1"
20 FOR Z=1 TO 15
30 PRINT I$
40 O$=""
50 FOR I=1 TO LEN(I$)
60 C=1
70 IF MID$(I$,I,1)=MID$(I$,I+C,1) THEN C=C+1: GOTO 70
80 O$=O$+CHR$(C+48)+MID$(I$,I,1)
90 I=I+C-1
100 NEXT I
110 I$=O$
120 NEXT Z</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 cls
110 dim x$(2)
120 i = 0 ' índice de cadena de entrada
130 x$(i) = "1"
140 input "Indica cuantas repeticiones: ",r
150 print "Secuencia:"
160 print x$(i)
170 for n = 1 to r-1
180 j = 1-i ' índice de cadena de salida
190 x$(j) = ""
200 k = 1
210 while k <= len(x$(i))
220 k0 = k+1
230 while ((k0 <= len(x$(i))) and (mid$(x$(i),k,1) = mid$(x$(i),k0,1)))
240 k0 = k0+1
250 wend
260 x$(j) = x$(j)+str$(k0-k)+mid$(x$(i),k,1)
270 k = k0
280 wend
290 i = j
300 print x$(j)
310 next n
320 end</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
 
==={{header|GW-BASIC}}===
The [[#BASIC|BASIC]] solution works without any changes.
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#BASIC|BASIC]] solution works without any changes.
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">LET i$ = "1"
FOR z = 1 TO 15
PRINT i$
LET o$ = ""
FOR i = 1 TO LEN(i$)
LET c = 1
DO WHILE (i$)[i:i+1-1] = (i$)[i+c:i+c+1-1]
LET c = c+1
LOOP
LET o$ = o$ & CHR$(c+48) & (i$)[i:i+1-1]
LET i = i+c-1
NEXT i
LET i$ = o$
NEXT z
END</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
 
=={{header|BASIC256}}==
Line 1,793 ⟶ 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 3,125 ⟶ 3,265:
"31131211131221"
"13211311123113112211" */</syntaxhighlight>
 
Implementation treating the sequence as numbers
 
<syntaxhighlight lang="maxima">
ciphers(n):=block(makelist(floor(mod(n, 10^(k+1)) / 10^k), k, 0,floor(log(n)/log(10))),reverse(%%));
 
collect(a) := block(
[n: length(ciphers(a)), b: [ ], x: ciphers(a)[1], m: 1],
for i from 2 thru n do
(if ciphers(a)[i] = x then m: m + 1 else (b: endcons([x, m], b), x: ciphers(a)[i], m: 1)),
b: endcons([x, m], b),
map(reverse,%%),
flatten(%%),
at(sum((part(%%,k))*y^(length(%%)-k),k,1,length(%%)),y=10)
)$
 
block(i:1,append([i],makelist(i:collect(i),9)),table_form(%%));
/* matrix(
[1],
[11],
[21],
[1211],
[111221],
[312211],
[13112221],
[1113213211],
[31131211131221],
[13211311123113112211]
) */
</syntaxhighlight>
 
=={{header|MAXScript}}==
Line 4,599 ⟶ 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 4,958 ⟶ 5,163:
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program looksay;
s := "1";
loop for i in [1..10] do
print(s);
s := looksay(s);
end loop;
 
proc looksay(s);
loop for c in s do;
if cur /= c then
if count /= om then
r +:= count + cur;
end if;
cur := c;
count := 1;
else
count +:= 1;
end if;
end loop;
r +:= count + cur;
return r;
end proc;
end looksay;</syntaxhighlight>
{{out}}
<pre>1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211</pre>
=={{header|Sidef}}==
{{trans|Perl}}
Line 5,618 ⟶ 5,858:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">var lookAndSay = Fn.new { |s|
var res = ""
var digit = s[0]
2,111

edits