Hofstadter Figure-Figure sequences: Difference between revisions
Hofstadter Figure-Figure sequences (view source)
Revision as of 08:22, 31 December 2019
, 4 years agoAdded 11l
Alextretyak (talk | contribs) (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}}==
|