Jump to content

Simple Fibonacci genertor


e2e4au
 Share

Recommended Posts

; Fibonacci number generator, first 50 only

#include <array.au3>

Dim $fib1 = 1, $fib2 = 2, $fib3, $results[51], $temp

$results[1] = $fib1

$results[2] = $fib2

For $temp = 3 To 50

$fib3 = $fib1 + $fib2

$results[$temp] = $fib3

swap($fib1, $fib2, $fib3)

Next

_ArrayDisplay($results, "50 Fibonacci Numbers")

Func swap(ByRef $a, ByRef $b, ByRef $c)

$a = $b

$b = $c

EndFunc ;==>swap

Link to comment
Share on other sites

Nice script.

Keep it up!

peethebee

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Link to comment
Share on other sites

I have made something like that before, using an algorithm like this:

$a = 1
$b = 1
While 1
    $c = $a + $b
    $b = $c + $a
    $a = $b + $c
Wend
1 + 1 = 2
2 + 1 = 3
3 + 2 = 5
5 + 3 = 8
8 + 5 = 13
...
Very nice work though! I never thought about using arrays...
Link to comment
Share on other sites

I really don't want to seem rude but what exactly is the fibboncci (did I spell that right?) sequence good for :whistle:? I have heard about it several times but am not sure what it couldbe used for. Any idea or explanation will be appreciated, ty :dance: .

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Link to comment
Share on other sites

I really don't want to seem rude but what exactly is the fibboncci (did I spell that right?) sequence good for :dance:? I have heard about it several times but am not sure what it couldbe used for. Any idea or explanation will be appreciated, ty :( .

<{POST_SNAPBACK}>

No, excellent question...

I've seen this in fractint (program to make fractal imagery) but I still don't know exactly what it is for ... :whistle:

Hey anyone :dance: enough to make a fractal generator in AutoIt3? That WOULD be cool! Oh it needs to spin in 3d too (just kidding)

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Link to comment
Share on other sites

Ok here's something like 200 pages worth of information on Fibonacci numbers ...

Fibonacci Numbers and the Golden Section

Can you believe it all started with someone observing rabbits?

And here's that program I lost so much time on trying different formulas and combinations ... WELCOME to the Fractint WWW pages

Really an awesome program. Look ma, no drugs :whistle:

I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Link to comment
Share on other sites

  • 14 years later...

thx, small change for n fibonacci:

Fibonacci(14,1)

Func Fibonacci($limit=50,$display=0)
   Dim $fib1 = 1, $fib2 = 2, $fib3, $results[$limit], $temp
   $results[0] = $fib1
   $results[1] = $fib2
   For $temp = 2 To $limit-1
      $fib3 = $fib1 + $fib2
      $results[$temp] = $fib3
      swap($fib1, $fib2, $fib3)
   Next
   If $display == 1 Then
      _ArrayDisplay($results, $limit & " Fibonacci Numbers")
   EndIf
   Return $results
EndFunc


Func swap(ByRef $a, ByRef $b, ByRef $c)
   $a = $b
   $b = $c
EndFunc ;==>swap

Link to comment
Share on other sites

  • Moderators

FYI necro-posting, while against forum etiquette, is really not report-worthy. A gentle statement for new folks is enough.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...