Mutual recursion: Difference between revisions
Content deleted Content added
Added Kotlin |
Add BaCon |
||
Line 337: | Line 337: | ||
0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 12 |
0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 12 |
||
</pre> |
</pre> |
||
=={{header|BaCon}}== |
|||
<lang freebasic>' Mutually recursive |
|||
FUNCTION F(int n) TYPE int |
|||
RETURN IIF(n = 0, 1, n - M(F(n -1))) |
|||
END FUNCTION |
|||
FUNCTION M(int n) TYPE int |
|||
RETURN IIF(n = 0, 0, n - F(M(n - 1))) |
|||
END FUNCTION |
|||
' Get iteration limit, default 20 |
|||
SPLIT ARGUMENT$ BY " " TO arg$ SIZE args |
|||
limit = IIF(args > 1, VAL(arg$[1]), 20) |
|||
FOR i = 0 TO limit |
|||
PRINT F(i) FORMAT "%2d " |
|||
NEXT |
|||
PRINT |
|||
FOR i = 0 TO limit |
|||
PRINT M(i) FORMAT "%2d " |
|||
NEXT |
|||
PRINT</lang> |
|||
{{out}} |
|||
<pre>prompt$ ./mutually-recursive |
|||
1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9 10 11 11 12 13 |
|||
0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 12</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |