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




 
\\ set console 70 characters by 40 lines
Form 70, 40
Module CheckSubs {
      Flush
      Document one$, two$
      For i =0 to 20
            Print format$("{0::-3}",i);
            f(i)
            \\  number pop then top value of stack
            one$=format$("{0::-3}",number)
            m(i)
            two$=format$("{0::-3}",number)
      Next i 
      Print
      Print one$
      Print two$
      Sub f(x)
            if x<=0 then Push 1 : Exit sub
            f(x-1)  ' leave result to for m(x)
            m()  
            push x-number
      End Sub
      Sub m(x)
            if x<=0 then Push 0 : Exit sub
            m(x-1)
            f()
            push x-number
      End Sub    
}
CheckSubs
 
Module Checkit {
      Function global f(n) {
            if n=0 then =1: exit
            if n>0 then  =n-m(f(n-1))     
      }
      Function global m(n) {
            if n=0 then =0
            if n>0 then  =n-f(m(n-1)) 
 
      }
      Document one$, two$
      For i =0 to 20
            Print format$("{0::-3}",i);
            one$=format$("{0::-3}",f(i))
            two$=format$("{0::-3}",m(i))
      Next i
      Print
      Print one$
      Print two$
}
Checkit
Module Checkit2 {
      Group Alfa {
            function f(n) {
                  if n=0 then =1: exit
                  if n>0 then  =n-.m(.f(n-1))     
            }
            function m(n) {
                  if n=0 then =0
                  if n>0 then  =n-.f(.m(n-1))     
            }
      }
      Document one$, two$
      For i =0 to 20
            Print format$("{0::-3}",i);
            one$=format$("{0::-3}",Alfa.f(i))
            two$=format$("{0::-3}",Alfa.m(i))
      Next i
      Print
      Print one$
      Print two$
      Clipboard one$+{
      }+two$
}
Checkit2
 
 