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

Published on 12 May 2024 09:40 PM
#Oz

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

Source code in the oz programming language

declare
  fun {F N}
     if N == 0 then 1
     elseif N > 0 then N - {M {F N-1}}
     end
  end

  fun {M N}
     if N == 0 then 0
     elseif N > 0 then N - {F {M N-1}}
     end
  end
in
  {Show {Map {List.number 0 9 1} F}}
  {Show {Map {List.number 0 9 1} M}}

  

You may also check:How to resolve the algorithm Add a variable to a class instance at runtime step by step in the Forth programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the NATURAL programming language
You may also check:How to resolve the algorithm Faulhaber's formula step by step in the C programming language
You may also check:How to resolve the algorithm HTTP step by step in the Raku programming language
You may also check:How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the Nim programming language