Hofstadter Figure-Figure sequences: Difference between revisions

Content added Content deleted
(add FreeBASIC)
Line 1,089: Line 1,089:
( scratchpad ) 40 iota [ 1 + ffr ] map 960 iota [ 1 + ffs ] map append 1000 iota 1 v+n set= .
( scratchpad ) 40 iota [ 1 + ffr ] map 960 iota [ 1 + ffs ] map append 1000 iota 1 v+n set= .
t</lang>
t</lang>

=={{header|FreeBASIC}}==
{{trans|BBC-BASIC}}
<lang freebasic>function ffr( n as integer ) as integer
if n = 1 then return 1
dim as integer i, j, r=1, s=1, v(1 to 2*n+1)
v(1) = 1
for i = 2 to n
for j = s to 2*n
if v(j) = 0 then exit for
next j
v(j) = 1
s = j
r += s
if r <= 2*n then v(r) = 1
next i
return r
end function

function ffs( n as integer ) as integer
if n = 1 then return 2
dim as integer i, j, r=1, s=2, v(1 to 2*n+1)
for i = 1 to n
for j = s to 2*n
if v(j) = 0 then exit for
next j
v(j) = 1
s = j
r += s
if r <= 2*n then v(r) = 1
next i
return s
end function

dim as integer i
print " R"," S"
print
for i = 1 to 10
print ffr(i), ffs(i)
next i

dim as boolean found(1 to 1000), failed
for i = 1 to 40
found(ffr(i)) = true
next i
for i = 1 to 960
found(ffs(i)) = true
next i
for i = 1 to 1000
if found(i) = false then failed = true
next i

if failed then print "Oh no!" else print "All integers from 1 to 1000 accounted for"</lang>
{{out}}<pre>
R S

1 2
3 4
7 5
12 6
18 8
26 9
35 10
45 11
56 13
69 14
All integers from 1 to 1000 accounted for
</pre>


=={{header|Go}}==
=={{header|Go}}==