2016-12-05 22:15:40 +01:00
|
|
|
/*REXX program shows mutual recursion (via the Hofstadter Male and Female sequences). */
|
|
|
|
|
parse arg lim .; if lim=='' then lim=40 /*assume the default for LIM? */
|
2020-02-17 23:21:07 -08:00
|
|
|
w= length(lim); $m.=.; $m.0= 0; $f.=.; $f.0= 1; Js=; Fs=; Ms=
|
2013-04-10 21:29:02 -07:00
|
|
|
|
2020-02-17 23:21:07 -08:00
|
|
|
do j=0 for lim+1
|
|
|
|
|
Js= Js right(j, w); Fs= Fs right( F(j), w); Ms= Ms right( M(j), w)
|
2015-11-18 06:14:39 +00:00
|
|
|
end /*j*/
|
2016-12-05 22:15:40 +01:00
|
|
|
say 'Js=' Js /*display the list of Js to the term.*/
|
|
|
|
|
say 'Fs=' Fs /* " " " " Fs " " " */
|
|
|
|
|
say 'Ms=' Ms /* " " " " Ms " " " */
|
|
|
|
|
exit /*stick a fork in it, we're all done. */
|
|
|
|
|
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
2020-02-17 23:21:07 -08:00
|
|
|
F: procedure expose $m. $f.; parse arg n; if $f.n==. then $f.n= n-M(F(n-1)); return $f.n
|
|
|
|
|
M: procedure expose $m. $f.; parse arg n; if $m.n==. then $m.n= n-F(M(n-1)); return $m.n
|