Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,7 @@
define method factorial (n)
if (n < 1)
error("invalid argument");
else
reduce1(\*, range(from: 1, to: n))
end
end method;

View file

@ -0,0 +1,11 @@
define method factorial (n)
if (n < 1)
error("invalid argument");
else
let total = 1;
for (i from n to 2 by -1)
total := total * i;
end;
total
end
end method;

View file

@ -0,0 +1,13 @@
define method factorial (n)
if (n < 1)
error("invalid argument");
end;
local method loop (n)
if (n <= 2)
n
else
n * loop(n - 1)
end
end;
loop(n)
end method;

View file

@ -0,0 +1,16 @@
define method factorial (n)
if (n < 1)
error("invalid argument");
end;
// Dylan implementations are required to perform tail call optimization so
// this is equivalent to iteration.
local method loop (n, total)
if (n <= 2)
total
else
let next = n - 1;
loop(next, total * next)
end
end;
loop(n, n)
end method;