Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -1,14 +0,0 @@
begin
comment factorial - algol 60;
integer procedure factorial(n); integer n;
begin
integer i,fact;
fact:=1;
for i:=2 step 1 until n do
fact:=fact*i;
factorial:=fact
end;
integer i;
for i:=1 step 1 until 10 do outinteger(1,factorial(i));
outstring(1,"\n")
end

View file

@ -1,5 +0,0 @@
PROC factorial = (INT upb n)LONG LONG INT:(
LONG LONG INT z := 1;
FOR n TO upb n DO z *:= n OD;
z
); ~

View file

@ -1,30 +0,0 @@
INT g = 7;
[]REAL p = []REAL(0.99999999999980993, 676.5203681218851, -1259.1392167224028,
771.32342877765313, -176.61502916214059, 12.507343278686905,
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7)[@0];
PROC complex gamma = (COMPL in z)COMPL: (
# Reflection formula #
COMPL z := in z;
IF re OF z < 0.5 THEN
pi / (complex sin(pi*z)*complex gamma(1-z))
ELSE
z -:= 1;
COMPL x := p[0];
FOR i TO g+1 DO x +:= p[i]/(z+i) OD;
COMPL t := z + g + 0.5;
complex sqrt(2*pi) * t**(z+0.5) * complex exp(-t) * x
FI
);
OP ** = (COMPL z, p)COMPL: ( z=0|0|complex exp(complex ln(z)*p) );
PROC factorial = (COMPL n)COMPL: complex gamma(n+1);
FORMAT compl fmt = $g(-16, 8)"⊥"g(-10, 8)$;
test:(
printf(($q"factorial(-0.5)**2="f(compl fmt)l$, factorial(-0.5)**2));
FOR i TO 9 DO
printf(($q"factorial("d")="f(compl fmt)l$, i, factorial(i)))
OD
)

View file

@ -1,7 +0,0 @@
PROC factorial = (INT n)LONG LONG INT:
CASE n+1 IN
1,1,2,6,24,120,720 # a brief lookup #
OUT
n*factorial(n-1)
ESAC
; ~

View file

@ -1,15 +0,0 @@
begin
% computes factorial n iteratively %
integer procedure factorial( integer value n ) ;
if n < 2
then 1
else begin
integer f;
f := 2;
for i := 3 until n do f := f * i;
f
end factorial ;
for t := 0 until 10 do write( "factorial: ", t, factorial( t ) );
end.

View file

@ -0,0 +1,25 @@
scope # factorials using the arbitrary precision mapm library
import mapm; # explicit import needed for: Linux, Mac OS X, Windows and Solaris
mapm.xdigits( 100 ); # need to set the precision - 100 is enough for 60!
# computes factorial n iteratively, using mapm
local constant factorial := proc( n :: number ) :: xnumber
if n < 2 then return mapm.xnumber( 1 )
else
local f := mapm.xnumber( 2 );
for i from 3 to n do f := f * i od;
return f
fi
end;
# returns a string representation of the integer portion of an xnumber
local constant asstring := proc( n :: xnumber ) :: string
local constant str := mapm.xtostring( n );
local constant point := "." in str;
return if point <> null then str[ 1 to point - 1 ] else str fi;
end;
for t from 0 to 9 do printf( "%2d! is %d\n", t, mapm.xtonumber( factorial( t ) ) ) od;
for t from 10 to 60 by 10 do printf( "%2d! is %s\n", t, asstring( factorial( t ) ) ) od;
end

View file

@ -0,0 +1,2 @@
> [(*)/ₒ 1 ( 1 x 1)] 7
5040

View file

@ -0,0 +1,16 @@
> :asm [(*)/ₒ 1 ( 1 x 1)]
mov x6, x0
mov x0, #0x1
mov x2, #0x1
eor x1, x1, x1
cmp x1, x6
b.GE apple_1
apple_0:
mul x0, x0, x2
add x2, x2, #0x1
add x1, x1, #0x1
cmp x1, x6
b.LT apple_0
apple_1:
ret

View file

@ -0,0 +1,19 @@
rem - return n!
def fn.factorial(n)
f = 1
for i = 1 to n
f = f * i
next i
fn.factorial = f
return
fend
print "Factorial Calculator"
print
print " n n!"
print "-------------------"
for k = 1 to 14
print using "## ###,###,###,###"; k; fn.factorial(k)
next k
end

View file

@ -0,0 +1,3 @@
create or replace function factorial(n) as (
list_reduce( list_transform(range(1,n+1), x -> x::HUGEINT), (prod,n) -> prod * n)
);

View file

@ -0,0 +1,3 @@
create or replace function double_precision_factorial(n) as (
list_product( range(1, n+1) )
);

View file

@ -0,0 +1,2 @@
select n, n!, factorial(n), double_precision_factorial(n)
from values (4), (30), (33) t(n);

View file

@ -0,0 +1,18 @@
(do
(fn factorial [n] ;;; iterative factorial
(if (< n 2)
1
;else
(do (var f 2)
(for [i 3 n]
(set f (* f i))
)
f
)
)
)
(for [n 0 10]
(io.write (string.format "%2d! = %s\n" n (factorial n)))
)
)

View file

@ -0,0 +1,12 @@
(
(n) let
1 (product) let
(n 1 >=)
(
product n * (product) bind
n 1 - (n) bind
) while
product
) (factorial) lambda
5 factorial puts pop

View file

@ -0,0 +1,30 @@
local bigint = require "pluto:bigint"
class Factorial
static function iterative(n)
local fact = bigint.new(1)
if n < 2 then return fact end
for i = 2, n do fact *= bigint.new(i) end
return fact
end
static function recursive(n)
if n < 2 then return bigint.new(1) end
return bigint.new(n) * Factorial.recursive(n - 1)
end
end
local function commatize(n)
local s = n:tostring()
local zero = bigint.new(0)
if n < zero then s = s:sub(2) end
for i = #s - 3, 1, -3 do
s = s:sub(1, i) .. "," .. s:sub(i + 1)
end
if n >= zero then return s end
return "-" .. s
end
local n = 24
print($"Factorial({n}) iterative -> {commatize(Factorial.iterative(n))}")
print($"Factorial({n}) recursive -> {commatize(Factorial.recursive(n))}")

View file

@ -1,20 +1,17 @@
-- 8 May 2025
-- 30 Jul 2025
include Settings
say 'FACTORIAL'
say 'Factorial'
say version
say
call First20
call Imp 10,'1 10 100 1000 10000 100000 1000000 10000000 100000000 130202808'
call Rec 10,'1 10 100 1000 10000 100000 200000'
call Imp 100,'69'
call Imp 1000,'449'
call Imp 10000,'3248'
call Imp 100000,'25205'
call Imp 10, '1 13 71 450 3249 25206 205022 1723508 14842907 130202808'
call ReC 10, '1 13 71 450 3249 25206 205022'
call Imp 1E6,'1 13 71 450 3249 25206'
exit
First20:
say 'First 20 factorials...'
say 'First 20 FactorialS...'
numeric digits 30
do n = 1 to 20
say n'! =' Fact(n)
@ -23,35 +20,35 @@ say
return
Imp:
glob. = ''
call ResetMemo
call Time('r')
arg d,p
numeric digits d; fact. = 0
numeric digits d; Fact. = 0
say 'Imperative in' d 'digits precision...'
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 right(f'!',10) 'has exact' right(Length(h),9) 'digits' '('Format(Time('e'),,3)'s)'
say Right(f'!',10) 'has exact' Right(Length(h),9) 'digits' '('Format(Time('e'),,3)'s)'
else
say right(f'!',10) 'has about' right(e+1,9) 'digits' '('Format(Time('e'),,3)'s)'
say Right(f'!',10) 'has about' Right(e+1,9) 'digits' '('Format(Time('e'),,3)'s)'
end
say
return
Rec:
glob. = ''
ReC:
call ResetMemo
call Time('r')
arg d,p
numeric digits d; fact. = 0
numeric digits d; Fact. = 0
say 'Recursive in' d 'digits precision...'
do i = 1 to Words(p)
call Time('r'); f = Word(p,i); h = Recursive(f)
parse var h 'E' e
if e = '' then
say right(f'!',10) 'has exact' right(Length(h),9) 'digits' '('Format(Time('e'),,3)'s)'
say Right(f'!',10) 'has exact' Right(Length(h),9) 'digits' '('Format(Time('e'),,3)'s)'
else
say right(f'!',10) 'has about' right(e+1,9) 'digits' '('Format(Time('e'),,3)'s)'
say Right(f'!',10) 'has about' Right(e+1,9) 'digits' '('Format(Time('e'),,3)'s)'
end
say
return
@ -64,6 +61,4 @@ if xx = 0 then
else
return xx*Recursive(xx-1)
include Functions
include Special
include Abend
include Math

View file

@ -0,0 +1,5 @@
#lang rhombus/static
fun factorial:
| factorial(0): 1
| factorial(n): n * factorial(n - 1)

View file

@ -0,0 +1,7 @@
#lang rhombus/static
fun factorial(n):
for values(a=1) (n in 1..=n):
a * n
factorial(6) // output: 720

View file

@ -0,0 +1,14 @@
factorial (n) iterative:
p =: 1
?# i =: from 2 upto n \ does nothing if n < 2
p =* i
:> p
factorial (n) recursive:
? n <= 1
:> 1
:> n * factorial recursive n-1
\ test code
main(parms):+
arg =: string parms[1] as integer else 100
print factorial arg iterative
print factorial arg recursive

View file

@ -0,0 +1 @@
¡

View file

@ -0,0 +1 @@
ɾƒ*

View file

@ -0,0 +1 @@
λ0=[1|x*];