Recaman's sequence: Difference between revisions
Content deleted Content added
Not a robot (talk | contribs) Add APL |
Not a robot (talk | contribs) Add BASIC |
||
Line 438: | Line 438: | ||
terms needed to generate integers 0 - 1000: 328002 |
terms needed to generate integers 0 - 1000: 328002 |
||
</pre> |
</pre> |
||
=={{header|BASIC}}== |
|||
<lang BASIC>10 DEFINT A-Z: DIM A(100) |
|||
20 PRINT "First 15 terms:" |
|||
30 FOR N=0 TO 14: GOSUB 100: PRINT A(N);: NEXT |
|||
35 PRINT |
|||
40 PRINT "First repeated term:" |
|||
50 GOSUB 100 |
|||
55 FOR M=0 TO N-1: IF A(M)=A(N) THEN 70 ELSE NEXT |
|||
60 N=N+1: GOTO 50 |
|||
70 PRINT "A(";N;") =";A(N) |
|||
80 END |
|||
100 IF N=0 THEN A(0)=0: RETURN |
|||
110 X = A(N-1)-N: IF X<0 THEN 160 |
|||
120 FOR M=0 TO N-1 |
|||
130 IF A(M)=X THEN 160 |
|||
140 NEXT |
|||
150 A(N)=X: RETURN |
|||
160 A(N)=A(N-1)+N: RETURN</lang> |
|||
{{out}} |
|||
<pre>First 15 terms: |
|||
0 1 3 6 2 7 13 20 12 21 11 22 10 23 9 |
|||
First repeated term: |
|||
A( 24 ) = 42</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |