Difference between revisions of "Mutual recursion"

From Fōrmulæ wiki
Jump to: navigation, search
m (Solution)
(Description (from Rosetta Code))
 
Line 3: Line 3:
 
=== Description (from Rosetta Code) ===
 
=== Description (from Rosetta Code) ===
  
Two functions are said to be mutually recursive if the first calls the second, and in turn the second calls the first.
+
{| class="wikitable" style="width:100%;"
 +
| Two functions are said to be mutually recursive if the first calls the second, and in turn the second calls the first.
  
 
Write two mutually recursive functions that compute members of the [http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Female_and_Male_sequences Hofstadter Female and Male sequences] defined as:
 
Write two mutually recursive functions that compute members of the [http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Female_and_Male_sequences Hofstadter Female and Male sequences] defined as:
Line 18: Line 19:
  
 
(If a language does not allow for a solution using mutually recursive functions then state this rather than give a solution by other means).
 
(If a language does not allow for a solution using mutually recursive functions then state this rather than give a solution by other means).
 +
|}
  
 
=== Solution ===
 
=== Solution ===

Latest revision as of 17:44, 23 March 2019

This page is the answer to the task Mutual recursion in the Rosetta Code.

Description (from Rosetta Code)

Two functions are said to be mutually recursive if the first calls the second, and in turn the second calls the first.

Write two mutually recursive functions that compute members of the Hofstadter Female and Male sequences defined as:

(If a language does not allow for a solution using mutually recursive functions then state this rather than give a solution by other means).

Solution

The same program when the flowchart package visualization is selected. Click/tap to enlarge

MutualRecursionProgramCode.png

Example

MutualRecursionOutput1.png