RosettaCodeData/Task/Fusc-sequence/FutureBasic/fusc-sequence.basic

41 lines
603 B
Plaintext

_max = 20000000
begin globals
NSUInteger f(_max)
end globals
void local fn Fusc
f(0) = 0 : f(1) = 1
for NSUInteger n = 2 to _max
if ( n & 1 )
f(n) = f((n - 1) / 2) + f((n + 1) / 2)
else
f(n) = f(n / 2)
end if
next
end fn
void local fn DoIt
NSUInteger i, d = 0
fn Fusc
for i = 0 to 60
print f(i);" ";
if ( i == 32 ) then print
next
print : print : print @" index\t\t value"
for i = 0 to _max
if ( f(i) >= d )
printf @"%11lu\t\t%6lu",i,f(i)
if ( d == 0 ) then d = 1
d *= 10
end if
next
end fn
fn DoIt
HandleEvents