Skip to content

mhxion/nth_position_for_fibonacci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Nth position for a given Fibonacci number

This is small algorithmic script I cooked up while playing with fibonacci squence programs. The algorithm for finding the nth position is based on empirical scribbles.

Usage

The script returns a generator object which includes a single integer which is the position of the given fibonacci number.

from nth_for_fibonacci import nth_for_fib

print(list(nth_for_fib(10610209857723)))
# prints [100]

nth_for_fib() attribute should be used for any valid output.

Performance

The script generates a constant time complexity O(1). For a million iteration, it takes about 1.7 seconds on average.

timeit.timeit("nth_for_fib(2350704430272641239071841033501890806135341594051678146868727563621503575841361361660546174279787382902052764874870847641179)", "from __main__ import nth_for_fib", number=1000000)

# returns 1.705661797997891

Limitations

There are some limitations as I only get so much time to work on this. The only known limitations are:

  1. It can't tell if the given number doesn't belong the fibonacci group, as I didn't write anything to guard that.
  2. The script doesn't work or throws an error if the given value is over 8.88 x 10187 or over the 901th Fibonacci position. Possibly because of the nature of the Fibonacci series, for values over 8.88 x 10187 a new equation is required. I will be working on this.

Contribution

Contributions for issues, developments are welcome. Please make a pull request or open an issue.

License and Attribution

The script is © copyrighted under the MIT license, not the best license to ensure credition, I hope you won't mind.

About

Nth position for a given fibonacci number

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages