Liberty BASIC Community Forum
« [RC] Fibonacci n-step number sequences »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:00pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 sticky  Author  Topic: [RC] Fibonacci n-step number sequences  (Read 243 times)
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1179
xx [RC] Fibonacci n-step number sequences
« Thread started on: Dec 20th, 2016, 12:00pm »

Rosetta Code
These number series are an expansion of the ordinary Fibonacci sequence

Interesting variants on the usual Fibonacci.. instead of each new number being formed from the sum of the preceding two numbers, we form it from the sum of three or more terms. The Lewis versions simply start with a '2' instead of a '1'.

Code:
 Showing terms of Fibonacci series.
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
 Showing terms of Lewis Fibonacci series.
2 1 3 4 7 11 18 29 47 76 123 199 322 521 843

 Showing terms of tribonacci series.
1 1 2 4 7 13 24 44 81 149 274 504 927 1705 3136
 Showing terms of Lewis tribonacci series.
2 1 2 5 8 15 28 51 94 173 318 585 1076 1979 3640

 Showing terms of tetranacci series.
1 1 2 4 8 15 29 56 108 208 401 773 1490 2872 5536
 Showing terms of Lewis tetranacci series.
2 1 2 4 9 16 31 60 116 223 430 829 1598 3080 5937

 Showing terms of pentanacci series.
1 1 2 4 8 16 31 61 120 236 464 912 1793 3525 6930
 Showing terms of Lewis pentanacci series.
2 1 2 4 8 17 32 63 124 244 480 943 1854 3645 7166

 Showing terms of hexanacci series.
1 1 2 4 8 16 32 63 125 248 492 976 1936 3840 7617
 Showing terms of Lewis hexanacci series.
2 1 2 4 8 16 33 64 127 252 500 992 1968 3903 7742

 Showing terms of heptanacci series.
1 1 2 4 8 16 32 64 127 253 504 1004 2000 3984 7936
 Showing terms of Lewis heptanacci series.
2 1 2 4 8 16 32 65 128 255 508 1012 2016 4016 8000

 Showing terms of octonacci series.
1 1 2 4 8 16 32 64 128 255 509 1016 2028 4048 8080
 Showing terms of Lewis octonacci series.
2 1 2 4 8 16 32 64 129 256 511 1020 2036 4064 8112

 Showing terms of nonanacci series.
1 1 2 4 8 16 32 64 128 256 511 1021 2040 4076 8144
 Showing terms of Lewis nonanacci series.
2 1 2 4 8 16 32 64 128 257 512 1023 2044 4084 8160

 Showing terms of decanacci series.
1 1 2 4 8 16 32 64 128 256 512 1023 2045 4088 8172
 Showing terms of Lewis decanacci series.
2 1 2 4 8 16 32 64 128 256 513 1024 2047 4092 8180
 


My solution-
Code:
    for i =1 to 9
        read start$, prefix$
        print
        print " Showing terms of "; prefix$; "nacci series."
        print fib$( start$)
        start$ ="2" +mid$( start$, 2)
        print " Showing terms of Lewis "; prefix$; "nacci series."
        print fib$( start$)
    next i

    wait

function fib$( f$)
    n   =numTerms( f$)

    for j =n +1 to 15
        nxt =0
        for k =1 to n
             nxt =nxt +val( word$( f$, j -k, " "))
        next k
        f$  =f$ +" " +str$( nxt)
    next j

    fib$ =f$
end function

function numTerms( i$)
    numTerms =1
    for i =2 to len( i$)
        if mid$( i$, i, 1) =" " then numTerms =numTerms +1
    next i
end function

    data "1 1", "Fibo"
    data "1 1 2", "tribo"
    data "1 1 2 4", "tetra"
    data "1 1 2 4 8", "penta"
    data "1 1 2 4 8 16", "hexa"
    data "1 1 2 4 8 16 32", "hepta"
    data "1 1 2 4 8 16 32 64", "octo"
    data "1 1 2 4 8 16 32 64 128", "nona"
    data "1 1 2 4 8 16 32 64 128 256", "deca"
 


EDIT Someone put up a RunBASIC solution. It needs editing to match the ( refined?) version of the task, and to be runnable as-is...
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls