Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/Mutual-recursion/Modula-2/mutual-recursion.mod2
Normal file
38
Task/Mutual-recursion/Modula-2/mutual-recursion.mod2
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
MODULE MutualRecursion;
|
||||
FROM InOut IMPORT WriteCard, WriteString, WriteLn;
|
||||
|
||||
TYPE Fn = PROCEDURE(CARDINAL): CARDINAL;
|
||||
|
||||
PROCEDURE F(n: CARDINAL): CARDINAL;
|
||||
BEGIN
|
||||
IF n=0 THEN RETURN 1;
|
||||
ELSE RETURN n-M(F(n-1));
|
||||
END;
|
||||
END F;
|
||||
|
||||
PROCEDURE M(n: CARDINAL): CARDINAL;
|
||||
BEGIN
|
||||
IF n=0 THEN RETURN 0;
|
||||
ELSE RETURN n-F(M(n-1));
|
||||
END;
|
||||
END M;
|
||||
|
||||
(* Print the first few values of one of the functions *)
|
||||
PROCEDURE Show(name: ARRAY OF CHAR; fn: Fn);
|
||||
CONST Max = 15;
|
||||
VAR i: CARDINAL;
|
||||
BEGIN
|
||||
WriteString(name);
|
||||
WriteString(": ");
|
||||
FOR i := 0 TO Max DO
|
||||
WriteCard(fn(i), 0);
|
||||
WriteString(" ");
|
||||
END;
|
||||
WriteLn;
|
||||
END Show;
|
||||
|
||||
(* Show the first values of both F and M *)
|
||||
BEGIN
|
||||
Show("F", F);
|
||||
Show("M", M);
|
||||
END MutualRecursion.
|
||||
Loading…
Add table
Add a link
Reference in a new issue