How to resolve the algorithm Mutual recursion step by step in the REBOL programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Mutual recursion step by step in the REBOL 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 REBOL programming language
Source code in the rebol programming language
REBOL [
Title: "Mutual Recursion"
URL: http://rosettacode.org/wiki/Mutual_Recursion
References: [http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_Female_and_Male_sequences]
]
f: func [
"Female."
n [integer!] "Value."
] [either 0 = n [1][n - m f n - 1]]
m: func [
"Male."
n [integer!] "Value."
] [either 0 = n [0][n - f m n - 1]]
fs: [] ms: [] for i 0 19 1 [append fs f i append ms m i]
print ["F:" mold fs crlf "M:" mold ms]
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the REXX programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Tcl programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Wart programming language
You may also check:How to resolve the algorithm Least common multiple step by step in the OCaml programming language
You may also check:How to resolve the algorithm Roots of a function step by step in the REXX programming language