2016-12-05 22:15:40 +01:00
|
|
|
/*REXX program shows mutual recursion (via the Hofstadter Male and Female sequences). */
|
2020-02-17 23:21:07 -08:00
|
|
|
parse arg lim .; if lim='' then lim= 40; w= length(lim); pad= left('', 20)
|
2013-04-10 21:29:02 -07:00
|
|
|
|
2020-02-17 23:21:07 -08:00
|
|
|
do j=0 for lim+1; jj= right(j, w); ff= right(F(j), w); mm= right(M(j), w)
|
|
|
|
|
say pad 'F('jj") =" ff pad 'M('jj") =" mm
|
2015-11-18 06:14:39 +00:00
|
|
|
end /*j*/
|
2016-12-05 22:15:40 +01:00
|
|
|
exit /*stick a fork in it, we're all done. */
|
|
|
|
|
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
|
|
|
|
F: procedure; parse arg n; if n==0 then return 1; return n - M( F(n-1) )
|
|
|
|
|
M: procedure; parse arg n; if n==0 then return 0; return n - F( M(n-1) )
|