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:










F
(
0
)



=
1
 
;
 
M
(
0
)
=
0




F
(
n
)



=
n
−
M
(
F
(
n
−
1
)
)
,

n
>
0




M
(
n
)



=
n
−
F
(
M
(
n
−
1
)
)
,

n
>
0.






{\displaystyle {\begin{aligned}F(0)&=1\ ;\ M(0)=0\\F(n)&=n-M(F(n-1)),\quad n>0\\M(n)&=n-F(M(n-1)),\quad n>0.\end{aligned}}}





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




/* We need to predeclare M if we want F to be able to see it.
 * This is done using 'extern', same as if it had been in a
 * different compilation unit. */
extern M(byte n) byte;
 
/* Mutually recursive functions */
proc F(byte n) byte: 
    if n=0 then 1 else n - M(F(n-1)) fi 
corp
 
proc M(byte n) byte: 
    if n=0 then 0 else n - F(M(n-1)) fi
corp
 
/* Show the first 16 values of each */
proc nonrec main() void:
    byte i;
 
    write("F:");
    for i from 0 upto 15 do write(F(i):2) od;
    writeln();
 
    write("M:");
    for i from 0 upto 15 do write(M(i):2) od;
    writeln()
corp