Strict Standards: Declaration of action_plugin_importoldindex::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/lib/plugins/importoldindex/action.php on line 8

Strict Standards: Declaration of action_plugin_include::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/lib/plugins/include/action.php on line 140

Strict Standards: Declaration of action_plugin_discussion::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/lib/plugins/discussion/action.php on line 955

Strict Standards: Declaration of action_plugin_blog::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/lib/plugins/blog/action.php on line 154

Strict Standards: Declaration of action_plugin_importoldchangelog::register() should be compatible with DokuWiki_Action_Plugin::register($controller) in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/lib/plugins/importoldchangelog/action.php on line 157

Deprecated: Assigning the return value of new by reference is deprecated in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parserutils.php on line 205

Deprecated: Assigning the return value of new by reference is deprecated in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parserutils.php on line 208

Deprecated: Assigning the return value of new by reference is deprecated in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parserutils.php on line 389

Deprecated: Assigning the return value of new by reference is deprecated in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parserutils.php on line 530

Strict Standards: Declaration of cache_instructions::retrieveCache() should be compatible with cache::retrieveCache($clean = true) in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/cache.php on line 291

Deprecated: Function split() is deprecated in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/auth.php on line 154

Strict Standards: Only variables should be passed by reference in /freeola/users/0/0/sr0193000/htdocs/dokuwiki/doku.php on line 71
====== Fibonacci Generator Simple ====== A very basic Fibonacci sequence generator written in the Inform programming language. Inform is not a true programming language (as far as I understand it). It is designed to make the process of writing text adventures easier. As such it really isn't intended for this sort of thing, but I was quite impressed it was still capable of it. In any case, I like to write Fibonacci programs in new languages that I learn, so here is my basic Inform version. ===== Description ===== The Fibonacci algorithm was invented by an Italian mathematician (Fibonacci) to predict rabbit growth. A lot of assumptions are made, some of which are a bit sillier than others: Assume that you start with two rabbits.\\ Assume that once a rabbit is three years old, it is capable of mating.\\ Assume that all rabbits capable of mating will in fact mate.\\ Assume that every time two rabbits mate, one offspring is produced without failure; no more, no less.\\ Assume rabbits can only produce one 'litter' a year.\\ Assume that there is an almost equal number of male and female rabbits.\\ Assume rabbits never die.\\ Anyway, the interesting thing about the Fibonacci algorithm is that it can be implemented recursively, and the numbers get big VERY quickly. The most basic way of expressing the algorithm is shown below:\\ fib[n] = fib[n-1] + fib[n-2]\\ where fib[1] = 1, fib[2] = 1 ===== The Source Code ===== You can view all the source code of the program below. **fib.inf**:\\ [ Main twix n counter; n = 20; for (counter=1 : counter<(n+1) : counter++) { twix = Fib(counter); print "Fib(", counter, ") = ", twix, "^"; } ]; [ Fib n; if (n < 3) { return 1; } else { return (Fib(n-1) + Fib(n-2)); } ]; ===== Example of Use ===== To use the program change the line, "n = 20;" so that the number reflects whatever Fibonacci index you want. You should use something like the following line to compile (depends on your own install of Inform, change paths .etc): //Compile command (this is just one long line)//: ''C:\Inform\Lib\Base\Inform -s Fib \\ +include_path=.\,C:\Inform\Lib\Base,C:\Inform\Lib\Contrib \\ | more pause "at end of compilation"'' //Output//: ''Fib(//n//) = //fibnumber// \\ Fib(//n + 1//) = //next_fibnumber//'' ===== Assumptions ===== None, but for large Fibonacci indices, the computer will probably cause an overflow or hang. I wouldn't push it much above 50. --- //[[nex@n-e-x.co.uk|Nexami Engeo]] 2007/07/06 00:17// ~~DISCUSSION~~