Shop OBEX P1 Docs P2 Docs Learn Events
Fibonacci Series — Parallax Forums

Fibonacci Series

ArchiverArchiver Posts: 46,084
edited 2004-07-01 03:38 in General Discussion
Could anyone please help me figure out the PBASIC format for the
fibanacci series? (n1+n2=n3) (n2+n3=n4) etc. I am having trouble
programming this eqation into PBASIC.

Any help would be appreciated

-Jay

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-07-01 00:17
    You could try this code below. It compiles and runs, I hope it gives really
    a Fibonacci series. But it may help anyway.

    Klaus from Holland,
    we just lost the semi finals of the European football championship, Portugal
    won.

    PS Fibonacci was about my first programming task when I was in university.
    Punchcards, immense printing machines and a real IBM 370 for the entire
    site. The world has changed al lot since then :-).

    '{$STAMP BS2p}
    '{$PBASIC 2.5}

    n1 VAR Word
    n2 VAR Word
    n3 VAR Word

    ix VAR Word

    n1=1
    n2=2

    FOR ix=3 TO 20
    n3=n2+n1
    n1=n2
    n2=n3
    DEBUG DEC n3," "
    PAUSE 250
    NEXT
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-01 00:32
    ' {$PBASIC 2.5}
    ' standard Fibonacci Series generator
    ' 1,2,3,5,8,13,...,46368
    ' <per Tracy Allen>
    x VAR Word
    y VAR Word
    z VAR Word

    x=0
    y=1
    z=1
    DO
    debug ? z
    x = y
    y = z
    z = x + y
    LOOP UNTIL z<y



    > Could anyone please help me figure out the PBASIC format for the
    >fibanacci series? (n1+n2=n3) (n2+n3=n4) etc. I am having trouble
    >programming this eqation into PBASIC.
    >
    >Any help would be appreciated
    >
    >-Jay
  • ArchiverArchiver Posts: 46,084
    edited 2004-07-01 03:38
    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > ' {$PBASIC 2.5}
    > ' standard Fibonacci Series generator
    > ' 1,2,3,5,8,13,...,46368
    > ' <per Tracy Allen>
    > x VAR Word
    > y VAR Word
    > z VAR Word
    >
    > x=0
    > y=1
    > z=1
    > DO
    > debug ? z
    > x = y
    > y = z
    > z = x + y
    > LOOP UNTIL z<y

    Tracy,

    The simplicity of your code above made me realize I never heard
    of Fibonacci. However, I am much more educated after reading the
    following web site, which covers this topic in great details,
    including origins from the year 1202!

    http://library.thinkquest.org/27890/mainIndex.html

    Thanks (To the originator of the topic) for expanding my knowledge!
    =)

    Chris Savage
    Knight Designs
Sign In or Register to comment.