Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
40
Task/Factorial/Oberon-07/factorial.oberon
Normal file
40
Task/Factorial/Oberon-07/factorial.oberon
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
MODULE Factorial;
|
||||
IMPORT
|
||||
Out;
|
||||
|
||||
VAR
|
||||
i: INTEGER;
|
||||
|
||||
PROCEDURE Iterative(n: INTEGER): INTEGER;
|
||||
VAR
|
||||
i, r: INTEGER;
|
||||
BEGIN
|
||||
ASSERT(n >= 0);
|
||||
r := 1;
|
||||
FOR i := n TO 2 BY -1 DO
|
||||
r := r * i
|
||||
END;
|
||||
RETURN r
|
||||
END Iterative;
|
||||
|
||||
PROCEDURE Recursive(n: INTEGER): INTEGER;
|
||||
VAR
|
||||
r: INTEGER;
|
||||
BEGIN
|
||||
ASSERT(n >= 0);
|
||||
r := 1;
|
||||
IF n > 1 THEN
|
||||
r := n * Recursive(n - 1)
|
||||
END;
|
||||
RETURN r
|
||||
END Recursive;
|
||||
|
||||
BEGIN
|
||||
FOR i := 0 TO 9 DO
|
||||
Out.String("Iterative ");Out.Int(i,0);Out.String("! =");Out.Int(Iterative(i),8);Out.Ln;
|
||||
END;
|
||||
Out.Ln;
|
||||
FOR i := 0 TO 9 DO
|
||||
Out.String("Recursive ");Out.Int(i,0);Out.String("! =");Out.Int(Recursive(i),8);Out.Ln;
|
||||
END
|
||||
END Factorial.
|
||||
4
Task/Factorial/REXX/factorial-4.rexx
Normal file
4
Task/Factorial/REXX/factorial-4.rexx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
call time('r')
|
||||
numeric digits 999999999
|
||||
a = 10/3
|
||||
say length(a) time('e')
|
||||
67
Task/Factorial/REXX/factorial-5.rexx
Normal file
67
Task/Factorial/REXX/factorial-5.rexx
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
include Settings
|
||||
|
||||
say version; say 'Factorial'; say
|
||||
p = '10 20 52 104 208 416 1e3 1e4 1e5 1e6 1e7 1e8'
|
||||
call Val 100
|
||||
p = '10 20 52 104 208 416 1e3 1e4 1e5 1e6'
|
||||
call Dig 100
|
||||
call Dig 1000
|
||||
call Dig 3000
|
||||
p = '10 20 52 104 208 416 1e3 1e4 1e5'
|
||||
call Dig 40000
|
||||
call Dig 500000
|
||||
p = '10 20 52 104 208 416 1e3 1e4'
|
||||
call Dig 5000000
|
||||
exit
|
||||
|
||||
Val:
|
||||
call Time('r')
|
||||
arg d
|
||||
numeric digits d; fact. = 0
|
||||
say 'Precision is' d 'digits'
|
||||
do i = 1 to Words(p)
|
||||
call Time('r');f = Word(p,i); say f'!' '=' Fact(f) '('Format(Time('e'),,3)'s)'
|
||||
end
|
||||
say
|
||||
return
|
||||
|
||||
Dig:
|
||||
call Time('r')
|
||||
arg d
|
||||
numeric digits d; fact. = 0
|
||||
say 'Precision is' d 'digits'
|
||||
do i = 1 to Words(p)
|
||||
call Time('r'); f = Word(p,i); h = Fact(f)
|
||||
parse var h 'E' e
|
||||
if e = '' then
|
||||
say f'!' 'has exact' Length(h) 'digits' '('Format(Time('e'),,3)'s)'
|
||||
else
|
||||
say f'!' 'has about' e+1 'digits' '('Format(Time('e'),,3)'s)'
|
||||
end
|
||||
say
|
||||
return
|
||||
|
||||
Fact:
|
||||
/* Factorial = n! */
|
||||
procedure expose fact.
|
||||
arg x
|
||||
/* Current in memory? */
|
||||
if fact.factorial.x <> 0 then
|
||||
return fact.factorial.x
|
||||
/* Previous in memory? */
|
||||
w = x-1
|
||||
if fact.factorial.w = 0 then do
|
||||
/* Loop cf definition */
|
||||
y = 1
|
||||
do n = 2 to x
|
||||
y = y*n
|
||||
end
|
||||
fact.factorial.x = y
|
||||
end
|
||||
else
|
||||
/* Multiply */
|
||||
fact.factorial.x = fact.factorial.w*x
|
||||
return fact.factorial.x
|
||||
|
||||
include Functions
|
||||
include Abend
|
||||
|
|
@ -20,4 +20,5 @@
|
|||
(define (factorial n) (fold * 1 (range 1 n)))
|
||||
|
||||
(factorial 8)
|
||||
|
||||
;40320
|
||||
9
Task/Factorial/Scheme/factorial-5.scm
Normal file
9
Task/Factorial/Scheme/factorial-5.scm
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(define (range n)
|
||||
(let ((lst '()))
|
||||
(do ((i 1 (+ i 1)))
|
||||
((= i (+ n 1)))
|
||||
(set! lst (cons i lst)))
|
||||
(reverse lst)))
|
||||
|
||||
(define (fact n)
|
||||
(apply * (range n)))
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
templates factorial
|
||||
when <=0> do 1 !
|
||||
when <0..> $ * ($ - 1 -> factorial) !
|
||||
factorial templates
|
||||
when <|0..> do
|
||||
@ set 1;
|
||||
1..$ -> @ set $@ * $;
|
||||
$@ !
|
||||
end factorial
|
||||
|
|
|
|||
4
Task/Factorial/Tailspin/factorial-3.tailspin
Normal file
4
Task/Factorial/Tailspin/factorial-3.tailspin
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
templates factorial
|
||||
when <=0> do 1 !
|
||||
when <0..> $ * ($ - 1 -> factorial) !
|
||||
end factorial
|
||||
4
Task/Factorial/Tailspin/factorial-4.tailspin
Normal file
4
Task/Factorial/Tailspin/factorial-4.tailspin
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
factorial templates
|
||||
when <|=0> do 1 !
|
||||
when <|0..> do $ * ($ - 1 -> #) !
|
||||
end factorial
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env ys-0
|
||||
!yamlscript/v0
|
||||
|
||||
defn main(n):
|
||||
say: "$n! = $factorial(n)"
|
||||
defn main(n=10):
|
||||
say: "$n! -> $factorial(n)"
|
||||
|
||||
defn factorial(x):
|
||||
apply *: 2 .. x
|
||||
2 .. x: .mul(*)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue