Hey there, it looks like this is your first time here. May I suggest subscribing to this blog and checking out these articles.

SOME RANDOM DUDE

Actionscript 2.0 Fibonacci Class

24.09.05 @ 8:42 pm

This is about as simple as it gets, but I thought it may come to some use for someone out there.

If you’re unfamiliar with the Fibonacci sequence, here’s a short snippet from Wikipedia

The earliest known reference to Fibonacci numbers is contained in a book on meters by an Indian mathematician named Pingala called Chhandah-shastra (500 BC). As documented by Donald Knuth in The Art of Computer Programming, this sequence was described by the Indian mathematicians Gopala and Hemachandra in 1150, who were investigating the possible ways of exactly bin packing items of length 1 and 2. In the West, it was first studied by Leonardo of Pisa, who was also known as Fibonacci (c. 1200), to describe the growth of an idealized rabbit population. The numbers describe the number of pairs in the rabbit population after n months if it is assumed that

  • in the first month there is just one new-born pair,
  • new-born pairs become fertile from their second month on
  • each month every fertile pair begets a new pair, and
  • the rabbits never die

Suppose that in month n we have a pairs of fertile and newly born rabbits and in month n + 1 we have b pairs. In month n + 2 we will necessarily have a + b pairs, because all a pairs of rabbits from month n will be fertile and produce a pairs of offspring, while the newly born rabbits in b will not be fertile and will not produce offspring.

The equation goes as such:
F = n2 + n1
where n2 is the current number in the sequence and n1 is the number immediately preceding n2.

The equation produces the following sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, …

This sequence is surprisingly common in nature and has been applied in many mathematical equations. I’m really looking forward to using this for some sort of fractal experiment in Flash. Should be fun.

Download Fibonacci Class

Liked This Post?

Well then, post the article to del.icio.us and subscribe to Some Random Dude's RSS Feed.

Show some comment love.

Total Donations for October:

$2.00

Want to help a good cause? Want to get this number higher? Learn how.

7 Responses to “Actionscript 2.0 Fibonacci Class”

  1. Gravatar
    $0.00 in Comment Love for October

    it sounds like a multyplying thing that has no end (no factors that actualy die, right?) and can jam the computer if it’s performed in a computer.


  2. Gravatar
    $0.00 in Comment Love for October

    Huh?


  3. Gravatar
    $0.00 in Comment Love for October

    Great example of where generators are incredibly useful: You don’t have to supply a ’stop here’ point of a sequence, you can continue in ‘inifinity’. Python example:
    def fibonacci():
    a, b = 0, 1
    yield 0
    while True:
    yield b
    a, b = b, a + b

    And that’s all you need. Then you can do something like this:
    fib = fibonacci()
    fib.next() # 0
    fib.next() # 1
    fib.next() # 1
    fib.next() # 2
    fib.next() # 3
    fib.next() # 5

    … and so on.


  4. Gravatar
    $0.00 in Comment Love for October

    The indentation disappeared. ;/ Everything after ‘dev fibonacci():’ should be indented four spaces, everything after ‘while True:’ should be indented eight.


  5. […] Fibonacci generator […]



  6. Gravatar
    $0.00 in Comment Love for October

    this is much much much simpler

    output=(”The fibonacci sequence is 0,1,1,”);
    a=0;
    b=1;
    c=a+b;

    while(c


Leave a Reply

Additional Doodads

Subscribe to Some Random Dude

Related Entries:

Most Commented Pages



Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 432316 bytes) in /home/18293/domains/somerandomdude.net/html/wp-includes/cache.php on line 48