September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 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;

View file

@ -1,3 +0,0 @@
define method factorial(n)
reduce1(\*, range(from: 1, to: n));
end