Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/parser.php on line
66
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/lexer.php on line
292
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
22
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
49
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
213
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
241
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
295
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
328
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/handler.php on line
575
Deprecated: Function split() is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/lexer.php on line
510
Deprecated: Assigning the return value of new by reference is deprecated in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/xhtml.php on line
939
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Doku_Renderer_xhtml::_tocitem() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/html.php on line
741
Strict Standards: Non-static method Doku_Renderer_xhtml::_xmlEntities() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/xhtml.php on line
119
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Doku_Renderer_xhtml::_tocitem() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/html.php on line
741
Strict Standards: Non-static method Doku_Renderer_xhtml::_xmlEntities() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/xhtml.php on line
119
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Doku_Renderer_xhtml::_tocitem() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/html.php on line
741
Strict Standards: Non-static method Doku_Renderer_xhtml::_xmlEntities() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/xhtml.php on line
119
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Doku_Renderer_xhtml::_tocitem() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/html.php on line
741
Strict Standards: Non-static method Doku_Renderer_xhtml::_xmlEntities() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/xhtml.php on line
119
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Doku_Renderer_xhtml::_tocitem() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/html.php on line
741
Strict Standards: Non-static method Doku_Renderer_xhtml::_xmlEntities() should not be called statically in
/freeola/users/0/0/sr0193000/htdocs/dokuwiki/inc/parser/xhtml.php on line
119
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.
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
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));
}
];
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
None, but for large Fibonacci indices, the computer will probably cause an overflow or hang. I wouldn't push it much above 50.
— Nexami Engeo 2007/07/06 00:17
Discussion