Fibonacci and Golden Ratio Primer Tutorial

C Recursion Primer Tutorial

Fibonacci and Golden Ratio Primer Tutorial

Wow! Never knew that C (with a recursive function) could be translated to Javascript so easily. That is, if the C is not full of pointer syntax that is, as Javascript is not like C with respect to its close relationship with the Kernel of some desktop operating systems. But variable declarations like “int” in C go to “var” in Javascript. C’s argc and argv[] command line thoughts can be like the web browser address bar ? and & arguments. In C when you scan for interactive input, we just use the Javascript prompt window, and the pointer scan uses just melts away. C’s printf can be changed to Javascript DOM document.getElementById(‘eleID’).innerHTML definitions.

Who’d have thought? But why are we doing this? Well, we heard this interesting talk … thanks, ABC … about the Fibonacci Sequence’s relationship to the Golden Ratio, both of which we’ve discussed separately at this blog, with C Recursion Primer Tutorial (as shown below) and Golden Ratio Game CSS Tutorial respectively. Looking up that code in the Fibonacci inspired C Recursion Primer Tutorial we realized how its recursive C approach to writing out some Fibonacci Sequence numbers could be adapted to some Javascript in an HTML web application we’ve written for you today, which you could call fibonacci_goldenratio.html and whose live run, run, would illustrate to you this Golden Ratio becoming closer and closer as the division of two adjacent numbers in the Fibonacci Sequence, the further into the sequence the closer that division is to the Golden Ratio (the irrational number approximating 1.61803398875 … compare below) … but you might get better with the web application and around the mid thirties into the Fibonacci Sequencing.

Here’s the mathematical fibonacci_goldenratio.html HTML and Javascript game source code, featuring “recursion” methodologies, that can be tried via this live run link, or below, in an HTML iframe element …


Previous relevant C Recursion Primer Tutorial is shown below.

C Recursion Primer Tutorial

C Recursion Primer Tutorial

Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. Specifically this defines an infinite number of instances (function values), using a finite expression that for some instances may refer to other instances, but in such a way that no loop or infinite chain of references can occur. The term is also used more generally to describe a process of repeating objects in a self-similar way.

Recursion is not just applicable to C. Already we have shown the same scenario, which you can compare and contrast, here, in Java, with Java Recursion Primer Tutorial, shown below. It is a good technique to use in many programming applications unless its use becomes too esoteric. It is usually true that a non-recursive technique can be used in place of the recursive technique. As you might guess, you can reduce the size of your code using recursion in your code. Recursive functions need an “anal” hard coded return, ahead of time, for the end-of-the-line value returned … as you see here for when i=1 or i=0 … if you don’t do this, it may be that your recursive function contributes to infinite looping … the stuff of nightmares.

Today’s tutorial in C(++) in Xcode shows you a way to find the path to your executable, the knowledge of which can then be applied to run the executable from a (Mac Terminal) Linux bash command line, as shown in the picture above and the last slide of the tutorial.

Link to Recursion information … via Wikipedia (as per information above).

This tutorial shows the use of a recursive function used to show the Fibonacci Sequence of a designated sequence size, both interactively or via (Mac Terminal application Linux bash) command line arguments.

Liber Abaci also posed, and solved, a problem involving the growth of a population of rabbits based on idealized assumptions. The solution, generation by generation, was a sequence of numbers later known as Fibonacci numbers. The number sequence was known to Indian mathematicians as early as the 6th century,[10][11][12] but it was Fibonacci’s Liber Abaci that introduced it to the West.

In the Fibonacci sequence of numbers, each number is the sum of the previous two numbers, starting with 0 and 1. This sequence begins 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 … [13]

The higher up in the sequence, the more closely the ratio of two consecutive Fibonacci numbers will approach the golden ratio (approximately 1 : 1.618 or 0.618 : 1).

Link to Fibonacci Sequence information … via Wikipedia (as per information above).

Link to … Elementary my dear Watson! … wow.

Download programming code and rename to main.cpp or main.c … depending on your environment.

If this was interesting you may be interested in this too.


Previous relevant (compare and contrast) Java Recursion Primer Tutorial is shown below.

Java Recursion Primer Tutorial

Java Recursion Primer Tutorial

Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. Specifically this defines an infinite number of instances (function values), using a finite expression that for some instances may refer to other instances, but in such a way that no loop or infinite chain of references can occur. The term is also used more generally to describe a process of repeating objects in a self-similar way.

Recursion is not just applicable to Java. It is a good technique to use in many programming applications unless its use becomes too esoteric. It is usually true that a non-recursive technique can be used in place of the recursive technique. As you might guess, you can reduce the size of your code using recursion in your code. Recursive functions need an “anal” hard coded return, ahead of time, for the end-of-the-line value returned … as you see here for when i=1 or i=0 … if you don’t do this, it may be that your recursive function contributes to infinite looping … the stuff of nightmares.

Link to Recursion information … via Wikipedia (as per information above).

This tutorial shows the use of a recursive function used to show the Fibonacci Sequence of a designated sequence size.

Liber Abaci also posed, and solved, a problem involving the growth of a population of rabbits based on idealized assumptions. The solution, generation by generation, was a sequence of numbers later known as Fibonacci numbers. The number sequence was known to Indian mathematicians as early as the 6th century,[10][11][12] but it was Fibonacci’s Liber Abaci that introduced it to the West.

In the Fibonacci sequence of numbers, each number is the sum of the previous two numbers, starting with 0 and 1. This sequence begins 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 … [13]

The higher up in the sequence, the more closely the ratio of two consecutive Fibonacci numbers will approach the golden ratio (approximately 1 : 1.618 or 0.618 : 1).

Link to Fibonacci Sequence information … via Wikipedia (as per information above).

Link to … Elementary my dear Watson! … wow.

Download programming code and rename to fibonacciRecursive.java

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Games, Tutorials and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *