Recaman's sequence: Difference between revisions

Content added Content deleted
No edit summary
(Added uBasic/4tH version)
Line 2,258: Line 2,258:
First duplicate term in the series is a(24) = 42
First duplicate term in the series is a(24) = 42
Terms up to a(328002) are needed to generate 0 to 1000</pre>
Terms up to a(328002) are needed to generate 0 to 1000</pre>

=={{header|uBasic/4tH}}==
<lang basic>a = 0 ' the first one is free ;-)
Print "First 15 numbers:"

For i = 1 Step 1 ' start loop
If i<16 Then Print a, ' print first 15 numbers
b = a-i ' try default first
If (b<1) + (Func(_Peek(Max(0, b))) = 1) Then b = a+i
If Func(_Peek(b)) = 1) Then Print "\nFirst repetition: ";b : Break
Proc _Set(Set(a, b)) ' set bit in bitmap
Next
End ' terminate program
' bitmap functions
_Set Param(1) : Let @(a@/32) = Func(_Poke(a@/32, a@%32)) : Return
_Poke Param(2) : Return (Or(@(a@), Shl(1, b@)))
_Peek Param(1) : Return (And(@(a@/32), Shl(1, a@%32))>0)
</lang>
{{out}}
<pre>
First 15 numbers:
0 1 3 6 2 7 13 20 12 21 11 22 10 23 9
First repetition: 42

0 OK, 0:459
</pre>


=={{header|VBScript}}==
=={{header|VBScript}}==