Hofstadter Figure-Figure sequences: Difference between revisions

Added 11l
(Added 11l)
Line 28:
* Wikipedia: [[wp:Hofstadter_sequence#Hofstadter_Figure-Figure_sequences|Hofstadter Figure-Figure sequences]].
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>V cR = [1]
V cS = [2]
 
F extend_RS()
V x = :cR[:cR.len-1] + :cS[:cR.len-1]
:cR [+]= (x)
:cS [+]= :cS.last+1 .< x
:cS [+]= (x + 1)
 
F ff_R(n)
assert(n > 0)
L n > :cR.len
extend_RS()
R :cR[n - 1]
 
F ff_S(n)
assert(n > 0)
L n > :cS.len
extend_RS()
R :cS[n - 1]
 
print((1..10).map(i -> ff_R(i)))
 
V arr = [0] * 1001
L(i) (40.<0).step(-1)
arr[ff_R(i)]++
L(i) (960.<0).step(-1)
arr[ff_S(i)]++
 
I all(arr[1..1000].map(a -> a == 1))
print(‘All Integers 1..1000 found OK’)
E
print(‘All Integers 1..1000 NOT found only once: ERROR’)</lang>
 
{{out}}
<pre>
[1, 3, 7, 12, 18, 26, 35, 45, 56, 69]
All Integers 1..1000 found OK
</pre>
 
=={{header|Ada}}==
1,480

edits