Anonymous user
Mutual recursion: Difference between revisions
Added Nemerle
(→{{header|Bc}}: OpenBSD bc also has the print statement.) |
(Added Nemerle) |
||
Line 861:
1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9 10 11 11 12 13 13 14 14 15
0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 12 13 14 14 15
=={{header|Nemerle}}==
There's probably some improvement that can be made here, but at least it illustrates the syntax for mutual recursion.
<lang Nemerle>using System;
using System.Console;
module Hofstadter
{
Hofstadter(m : int, start : string) : int
{
def F(n : int)
{
|0 => 1
|_ => n - M(F(n - 1))
}
and M(n : int)
{
|0 => 0
|_ => n - F(M(n - 1))
}
match(start)
{
|"F" => F(m)
|"M" => M(m)
}
}
Main() : void
{
foreach (n in [0 .. 20]) Write("{0} ", Hofstadter(n, "F"));
WriteLine();
foreach (n in [0 .. 20]) Write("{0} ", Hofstadter(n, "M"));
}
}</lang>
=={{header|Objective-C}}==
|