Mutual recursion: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: added/changed whitespace and comments, eliminated the need for a formatting function.) |
|||
Line 1,942:
=={{header|REXX}}==
===vanilla===
This version uses vertical formatting of the output.
<lang rexx>/*REXX program shows mutual recursion (via Hofstadter Male & Female
parse arg lim .;
say
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────one─liner subroutines─────────────────────*/
F:
M:
{{out}} using the default input of: <tt> 40 </tt>
<pre style="height:30ex">
Line 2,002 ⟶ 2,001:
This version uses memoization as well as a horizontal output format.
<br><br>The optimization due to memoization is faster by many orders of magnitude.
<lang rexx>/*REXX program shows mutual recursion (via Hofstadter Male & Female
parse arg lim .; if lim=='' then lim=
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. */
/*──────────────────────────────────one─liner
F:
M:
{{out}} using the default input of: <tt> 99 </tt>
<pre>
Line 2,027 ⟶ 2,025:
This version is identical in function to the previous example, but it also can compute and
<br>display a specific request (indicated by a negative number for the argument).
<lang rexx>/*REXX program shows mutual recursion (via Hofstadter Male & Female
/*If LIM is negative, only show a single result for the abs(lim) entry.*/
parse arg lim .; if lim=='' then lim=99; aLim=abs(lim)
end
if lim>0 then say 'Js=' Js; else say 'J('aLim")=" word(Js,aLim+1)
if lim>0 then say 'Fs=' Fs; else say 'F('aLim")=" word(Fs,aLim+1)
if lim>0 then say 'Ms=' Ms; else say 'M('aLim")=" word(Ms,aLim+1)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────one─liner
F:
M:
{{out}} using the input of: <tt> -70000 </tt>
<pre>
|