Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Fibonacci Numbers :D

Author
Message
Mr909
7
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 11th Dec 2012 22:54
Gets the position along the Fibonacci sequence for any number (n). I've personally found that utilizing the Fibonacci progression times a number often gives a steady increase that's useful for experience points and the like (it's never twice the number except from 2-3, therefore better than most exponential increases). Here ya go.

Just so you know, the reason the FOR loop is from 2 to n is because the first two numbers in the sequence are supposed to be 1. Depending on how you want to use this sequence, you might want to alter that.

Mr909
7
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 11th Dec 2012 23:04
Here's a little bonus function for any of you that have played any White Wolf Roleplaying games. It runs a dice pool similar to the ones they use.

BMacZero
13
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ N_America/ USA/ CA/ South
Posted: 20th Dec 2012 05:43
I wanted to point out that there is a closed form for Fibonacci numbers - it would be ideal to use this instead of iteration. What if I wanted the millionth or billionth Fibonacci number?

http://brianmacintosh.com
"'Who's that primitive entity accessing sliding collision data from my bridge?!', the troll roared." - TheComet
Mr909
7
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 26th Dec 2012 18:35
Oh, cool. Any chance you might have a function that utilizes that method?
BMacZero
13
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ N_America/ USA/ CA/ South
Posted: 26th Dec 2012 21:05 Edited at: 26th Dec 2012 21:05
I guess that would be useful . Here's one by spooky:

http://forum.thegamecreators.com/?m=forum_view&t=9622&b=10&msg=79084#m79084

Wikipedia describes the math:
http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_expression

http://brianmacintosh.com
"'Who's that primitive entity accessing sliding collision data from my bridge?!', the troll roared." - TheComet
Chris Tate
DBPro Master
10
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 23rd Jan 2013 16:52
Cool. Just wondering, what would be the advantage of using fibonacci over logarithms?

EG:


BMacZero
13
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ N_America/ USA/ CA/ South
Posted: 23rd Jan 2013 20:33 Edited at: 23rd Jan 2013 20:35
They have fairly different behaviors. It would depend on the application:

fibonacci sequence:


log(100)-log(100-x):


The Fibonacci sequence has some particularly special applications as more than just a curve (for example, as coefficients for Shell Sort).

http://brianmacintosh.com
"'Who's that primitive entity accessing sliding collision data from my bridge?!', the troll roared." - TheComet

Login to post a reply

Server time is: 2019-08-24 07:43:03
Your offset time is: 2019-08-24 07:43:03