How to resolve the algorithm Mutual recursion step by step in the Ring programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mutual recursion step by step in the Ring programming language

Table of Contents

Problem Statement

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).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Mutual recursion step by step in the Ring programming language

Source code in the ring programming language

see "F sequence : "
for i = 0 to 20
    see "" + f(i) + " "
next 
see nl
see "M sequence : "
for i = 0 to 20
    see "" + m(i) + " "
next
 
func f n
     fr = 1
     if n != 0 fr = n - m(f(n - 1)) ok
     return fr
 
func m n
     mr = 0
     if n != 0 mr = n - f(m(n - 1)) ok
     return mr

  

You may also check:How to resolve the algorithm Box the compass step by step in the LLVM programming language
You may also check:How to resolve the algorithm Entropy/Narcissist step by step in the Julia programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Read a configuration file step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the JavaScript programming language