Van Eck sequence: Difference between revisions

m
m (→‎{{header|Uiua}}: Reformat)
(14 intermediate revisions by 8 users not shown)
Line 365:
</pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="ABC">HOW TO RETURN vaneck.sequence length:
PUT {[1]: 0} IN seq
WHILE #seq < length:
PUT #seq-1 IN i
WHILE i>0 AND seq[i]<>seq[#seq]: PUT i-1 IN i
SELECT:
i=0: PUT 0 IN seq[#seq+1]
ELSE: PUT #seq-i IN seq[#seq+1]
RETURN seq
 
PUT vaneck.sequence 1000 IN eck
FOR i IN {1..10}: WRITE eck[i]>>4
WRITE /
FOR i IN {991..1000}: WRITE eck[i]>>4
WRITE /</syntaxhighlight>
{{out}}
<pre> 0 0 1 0 2 0 2 2 1 6
4 7 30 25 67 225 488 0 10 136</pre>
=={{header|Action!}}==
<syntaxhighlight lang="action!">INT FUNC LastPos(INT ARRAY a INT count,value)
Line 557 ⟶ 576:
0 0 1 0 2 0 2 2 1 6
4 7 30 25 67 225 488 0 10 136
</pre>
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
#include <basico.h>
 
algoritmo
decimales '0'
dimensionar(2) matriz de ceros (vaneck)
iterar para (i=2, #(i<=1000), ++i )
matriz.buscar en reversa(#(vaneck[i]),#(vaneck[1:i-1]))
---retener--- no es cero?, entonces{ menos'i' por'-1' }
meter en 'vaneck'
siguiente
 
imprimir ( "Van Eck: first 10 terms : ",#(vaneck[1:10]), NL,\
"Van Eck: terms 991 - 1000: ", #(vaneck[991:1000]), NL)
 
terminar
</syntaxhighlight>
{{out}}
<pre>
Van Eck: first 10 terms : 0,0,1,0,2,0,2,2,1,6
Van Eck: terms 991 - 1000: 4,7,30,25,67,225,488,0,10,136
</pre>
 
Line 958 ⟶ 1,003:
 
=={{header|BASIC}}==
{{works with|QBasic}}
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 DIM E(1000)
Line 972 ⟶ 1,018:
<pre> 0 0 1 0 2 0 2 2 1 6
4 7 30 25 67 225 488 0 10 136</pre>
 
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">limite = 1001
dim a(limite) fill 0
 
for n = 0 to limite-1
for m = n-1 to 0 step -1
if a[m] = a[n] then
a[n+1] = n-m
exit for
end if
next m
next n
 
print "Secuencia de Van Eck:" & Chr(10)
print "Primeros 10 terminos: ";
for i = 0 to 9
print a[i]; " ";
next i
print chr(10) & "Terminos 991 al 1000: ";
for i = 990 to 999
print a[i]; " ";
next i</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{trans|FreeBASIC}}
{{works with|Chipmunk Basic|3.6.4}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">100 cls
110 limite = 1000
120 dim a(limite)
130 '
140 for n = 0 to limite-1
150 for m = n-1 to 0 step -1
160 if a(m) = a(n) then
170 a(n+1) = n-m
180 exit for
190 endif
200 next m
210 next n
220 '
230 print "Secuencia de Van Eck:";chr$(10)
240 print "Primeros 10 terminos: ";
250 for i = 0 to 9
260 print a(i);
270 next i
280 print chr$(10);"Terminos 991 al 1000: ";
290 for i = 990 to 999
300 print a(i);
310 next i
320 end</syntaxhighlight>
 
==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">define limit = 1000
 
dim list[limit]
 
print "calculating van eck sequence..."
 
for n = 0 to limit - 1
 
for m = n - 1 to 0 step -1
 
if list[m] = list[n] then
 
let c = n + 1
let list[c] = n - m
 
break m
 
endif
 
wait
 
next m
 
next n
 
print "first 10 terms: "
 
for i = 0 to 9
 
print list[i]
 
next i
 
print "terms 991 to 1000: "
 
for i = 990 to 999
 
print list[i]
 
next i</syntaxhighlight>
{{out| Output}}<pre>calculating van eck sequence...
first 10 terms: 0 0 1 0 2 0 2 2 1 6
terms 991 to 1000: 4 7 30 25 67 225 488 0 10 136 </pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="vb">Const limite = 1000
 
Dim As Integer a(limite), n, m, i
 
For n = 0 To limite-1
For m = n-1 To 0 Step -1
If a(m) = a(n) Then a(n+1) = n-m: Exit For
Next m
Next n
 
Print "Secuencia de Van Eck:" &Chr(10)
Print "Primeros 10 terminos: ";
For i = 0 To 9
Print a(i) &" ";
Next i
Print Chr(10) & "Terminos 991 al 1000: ";
For i = 990 To 999
Print a(i) &" ";
Next i
End</syntaxhighlight>
{{out}}
<pre>Secuencia de Van Eck:
 
Primeros 10 terminos: 0 0 1 0 2 0 2 2 1 6
Terminos 991 al 1000: 4 7 30 25 67 225 488 0 10 136</pre>
 
==={{header|GW-BASIC}}===
{{trans|FreeBASIC}}
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">100 CLS
110 L = 1000
120 DIM A(L)
130 FOR N = 0 TO L
140 LET A(N) = 0
150 NEXT N
160 FOR N = 0 TO L-1
170 FOR M = N-1 TO 0 STEP -1
180 IF A(M) = A(N) THEN A(N+1) = N - M : GOTO 200
190 NEXT M
200 NEXT N
210 PRINT "Secuencia de Van Eck:"; CHR$(10)
220 PRINT "Primeros 10 terminos: ";
230 FOR I = 0 TO 9
240 PRINT A(I);
250 NEXT I
260 PRINT CHR$(10); "Terminos 991 al 1000: ";
270 FOR I = 990 TO 999
280 PRINT A(I);
290 NEXT I
300 END</syntaxhighlight>
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">If OpenConsole()
Define.i n, m, i, limite
limite = 1001
Dim a.i(limite)
For n = 0 To limite-1
For m = n-1 To 0 Step -1
If a(m) = a(n)
a(n+1) = n-m
Break
EndIf
Next m
Next n
PrintN("Secuencia de Van Eck:" + #CRLF$)
Print("Primeros 10 terminos: ")
For i = 0 To 9
Print(Str(a(i)) + " ")
Next i
Print(#CRLF$ + "Terminos 991 al 1000: ")
For i = 990 To 999
Print(Str(a(i)) + " ")
Next i
PrintN(#CRLF$ + "Press ENTER to exit" + #CRLF$ ): Input()
CloseConsole()
EndIf</syntaxhighlight>
 
==={{header|QBasic}}===
{{trans|FreeBASIC}}
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">CONST limite = 1000
DIM a(limite)
 
FOR n = 0 TO limite - 1
FOR m = n - 1 TO 0 STEP -1
IF a(m) = a(n) THEN
a(n + 1) = n - m
EXIT FOR
END IF
NEXT m
NEXT n
 
PRINT "Secuencia de Van Eck:"; CHR$(10)
PRINT "Primeros 10 terminos: ";
FOR i = 0 TO 9
PRINT a(i);
NEXT i
PRINT CHR$(10); "Terminos 991 al 1000: ";
FOR i = 990 TO 999
PRINT a(i);
NEXT i
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{trans|FreeBASIC}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Van Eck sequence"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
l = 1000
DIM a[l]
FOR n = 0 TO l-1
FOR m = n-1 TO 0 STEP -1
IF a[m] = a[n] THEN
a[n+1] = n-m
EXIT FOR
END IF
NEXT m
NEXT n
PRINT "Secuencia de Van Eck:"; CHR$(10)
PRINT "Primeros 10 terminos: ";
FOR i = 0 TO 9
PRINT a[i]; " ";
NEXT i
PRINT CHR$(10); "Terminos 991 al 1000: ";
FOR i = 990 TO 999
PRINT a[i]; " ";
NEXT i
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">limite = 1001
dim a(limite)
 
for n = 0 to limite-1
for m = n-1 to 0 step -1
if a(m) = a(n) then
a(n+1) = n-m
break
fi
next m
next n
 
print "Secuencia de Van Eck: \n"
print "Primeros 10 terminos: ";
for i = 0 to 9
print a(i), " ";
next i
print "\nTerminos 991 al 1000: ";
for i = 990 to 999
print a(i), " ";
next i
print</syntaxhighlight>
 
=={{header|BCPL}}==
Line 1,548 ⟶ 1,859:
4 7 30 25 67 225 488 0 10 136</pre>
 
=={{header|FreeBASICFōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Van_Eck_sequence}}
<syntaxhighlight lang="freebasic">
Const limite = 1000
 
'''Solution'''
Dim As Integer a(limite), n, m, i
 
[[File:Fōrmulæ - Van Eck sequence 01.png]]
For n = 0 To limite-1
For m = n-1 To 0 Step -1
If a(m) = a(n) Then a(n+1) = n-m: Exit For
Next m
Next n
 
'''Test case'''
Print "Secuencia de Van Eck:" &Chr(10)
Print "Primeros 10 terminos: ";
For i = 0 To 9
Print a(i) &" ";
Next i
Print Chr(10) & "Terminos 991 al 1000: ";
For i = 990 To 999
Print a(i) &" ";
Next i
End
</syntaxhighlight>
{{out}}
<pre>
Secuencia de Van Eck:
 
[[File:Fōrmulæ - Van Eck sequence 02.png]]
Primeros 10 terminos: 0 0 1 0 2 0 2 2 1 6
Terminos 991 al 1000: 4 7 30 25 67 225 488 0 10 136
</pre>
 
[[File:Fōrmulæ - Van Eck sequence 03.png]]
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Van_Eck_sequence}}
 
=={{header|Go}}==
Line 3,036 ⟶ 3,325:
First 10 terms: 8 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 16 183 0 6 21 10 249 0 5 48</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
, <Eck 1000>: e.Eck
, <First 10 e.Eck>: (e.First10) e.Rest1
, <Last 10 e.Eck>: (e.Rest2) e.Last10
= <Prout e.First10>
<Prout e.Last10>;
};
 
Eck {
s.N = <Reverse <Repeat s.N EckStep>>;
};
 
Reverse {
= ;
e.X s.I = s.I <Reverse e.X>;
};
 
Repeat {
0 s.F e.X = e.X;
s.N s.F e.X = <Repeat <- s.N 1> s.F <Mu s.F e.X>>;
};
 
EckStep {
= 0;
s.N e.X, e.X: e.F s.N e.R,
<Lenw e.F>: s.M e.F = <+ s.M 1> s.N e.X;
s.N e.X = 0 s.N e.X;
};</syntaxhighlight>
{{out}}
<pre>0 0 1 0 2 0 2 2 1 6
4 7 30 25 67 225 488 0 10 136</pre>
 
=={{header|REXX}}==
Line 3,251 ⟶ 3,573:
Terms 991 to 1000 are List(4, 7, 30, 25, 67, 225, 488, 0, 10, 136).
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program vaneck;
eck := [0];
 
loop for i in [1..999] do
prev := eck(..#eck-1);
eck(i+1) := i - (max/[j : e=prev(j) | e=eck(i)] ? i);
end loop;
 
print(eck(1..10));
print(eck(991..1000));
end program;</syntaxhighlight>
{{out}}
<pre>[0 0 1 0 2 0 2 2 1 6]
[4 7 30 25 67 225 488 0 10 136]</pre>
 
=={{header|SNOBOL4}}==
Line 3,292 ⟶ 3,630:
 
say van_eck(10)
say van_eck(1000).slicelast(991-1, 1000-110)</syntaxhighlight>
{{out}}
<pre>
Line 3,367 ⟶ 3,705:
vanEck(0..9) = 0 0 1 0 2 0 2 2 1 6
vanEck(990..999) = 4 7 30 25 67 225 488 0 10 136
 
=={{header|Uiua}}==
<syntaxhighlight lang="Uiua">
F ← ⊂⟨0◌|+1⟩>⊙(-1⧻),,⊗⊃⊢(↘1). # Generator function (prepends).
⇌⍥F999 [0] # Generate 1000 terms and flip.
⊃(&p↙¯)(&p↙∘)10 # Print first and last 10 terms.
</syntaxhighlight>
{{out}}
<pre>
[0 0 1 0 2 0 2 2 1 6]
[4 7 30 25 67 225 488 0 10 136]
</pre>
 
=={{header|Visual Basic .NET}}==
Line 3,414 ⟶ 3,764:
[4 7 30 25 67 225 488 0 10 136]
</pre>
 
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">1000 :1)=0
1010 I=1
1020 J=I-1
1030 #=J=0*1090
1040 #=:J)=:I)*1070
1050 J=J-1
1060 #=1030
1070 :I+1)=I-J
1080 #=1100
1090 :I+1)=0
1100 I=I+1
1110 #=I<1000*1020
1120 I=1
1130 #=1170
1140 I=991
1150 #=1170
1160 #=9999
1170 R=!
1180 N=10
1190 ?=:I)
1200 $=32
1210 I=I+1
1220 N=N-1
1230 #=N=0=0*1190
1240 ?=""
1250 #=R</syntaxhighlight>
{{out}}
<pre>0 0 1 0 2 0 2 2 1 6
4 7 30 25 67 225 488 0 10 136</pre>
 
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="javascriptwren">var max = 1000
var a = List.filled(max, 0)
var seen = {}
69

edits