Mutual recursion: Difference between revisions
Content deleted Content added
Line 613:
But you don't have to worry about that to use it.
=={{header|Eiffel}}==
<lang Eiffel>
class
APPLICATION
create
make
feature
make
-- Test of the mutually recursive functions Female and Male.
do
across
0 |..| 19 as c
loop
io.put_string (Female (c.item).out + " ")
end
io.new_line
across
0 |..| 19 as c
loop
io.put_string (Male (c.item).out + " ")
end
end
Female (n: INTEGER): INTEGER
-- Female sequence of the Hofstadter Female and Male sequences.
do
if n = 0 then
Result := 1
else
Result := n - Male (Female (n - 1))
end
end
Male (n: INTEGER): INTEGER
-- Male sequence of the Hofstadter Female and Male sequences.
do
if n = 0 then
Result := 0
else
Result := n - Female (Male (n - 1))
end
end
end
</lang>
{{out}}
<pre>
1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9 10 11 11 12
0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12
</pre>
=={{header|Elixir}}==
|