aboutsummaryrefslogtreecommitdiff
path: root/challenge-104/paulo-custodio/basic/ch-1.bas
blob: 52675c2fba554219f5c69bc992053e09e2c4e4c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
' Challenge 104
'
' TASK #1 � FUSC Sequence
' Submitted by: Mohammad S Anwar
' Write a script to generate first 50 members of FUSC Sequence. Please refer to
' OEIS for more information.
'
' The sequence defined as below:
'
' fusc(0) = 0
' fusc(1) = 1
' for n > 1:
' when n is even: fusc(n) = fusc(n / 2),
' when n is odd: fusc(n) = fusc((n-1)/2) + fusc((n+1)/2)

function fusc(n as integer) as integer
    if n=0 then
        fusc=0
    elseif n=1 then
        fusc=1
    elseif (n and 1)=0 then
        fusc=fusc(n/2)
    else
        fusc=fusc((n-1)/2)+fusc((n+1)/2)
    end if
end function

dim i as integer, n as integer
n=val(command(1))
for i=0 to n-1
    print fusc(i);" ";
next
print