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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mutual recursion step by step in the Ceylon 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 Ceylon programming language

Source code in the ceylon programming language

Integer f(Integer n)
    =>  if (n > 0)
        then n - m(f(n-1))
        else 1;

Integer m(Integer n)
    =>  if (n > 0)
        then n - f(m(n-1))
        else 0;

shared void run() {
    printAll((0:20).map(f));
    printAll((0:20).map(m));
}


  

You may also check:How to resolve the algorithm Reverse a string step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Make directory path step by step in the OCaml programming language
You may also check:How to resolve the algorithm RSA code step by step in the Scala programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the BQN programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the XLISP programming language