![]() |
fibonacci sequence
hi i am diving into programming and wanting to find out the amount of time it takes to execute a fibonacci sequence program. i have had past expirience with c++ so i have that code. to make sure the way the program runs is the same, i would like it if this program used while loops, and other similar things. here is the c++ code -
:
#include <iostream>so if anyone can "convert" this to python it would be appreciated |
Please see your other thread. Somewhere on the way there or back, invest some time in showing enough consideration to read the rules/FAQ. Sheesh.
|
~Moved
|
a c++ while loop and a python one might have different big-O complexity. if you don't know what i mean by that...that's what you're asking so google it. nobody gives a rat shit about how much time it takes to execute anything...b/c that data is relative to processor specs, etc.
how long does it take to drive to new york? see how vague that is? from where, how fast, how many stops, etc. that's why they have the big-O standard...it's absolute, not relative. certain alg's have specific growth rates. did you write that code? i enjoy clever shit like while(i--), because it's short and weird...but it's probably not good nowadays when the length of a text file isn't going to screw up any memory issues...you have room to be clear and comment, please do so. |
Complexity isn't everything. There are still plenty of applications, even on the desktop, where the difference in speed between C++ and a language like Python or Perl will be the difference between success and failure. It's why they have benchmarks.
|
yeah...that too. :)
you might look at the difference between different languages (as you may be doing already). if i knew python i'd convert it for you, but i don't. i'll probably screw with it next summer. use YOUR machine as an absolute reference and try different things...fib with loops, fib with recursion, etc. use different compilers and OS's if you can. this can be a pretty cool problem! |
~Re-moved
(My appologies to the OP. Should have read the entire thread before moving it the first time. |
:
n = 1000 |
I'd be tempted to use a generator:
:
|
Or perhaps:
:
|
| All times are GMT -5. The time now is 3:16 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC