This commit is contained in:
Ingy döt Net 2013-04-10 16:19:29 -07:00
parent e5e8880e41
commit 518da4a923
1019 changed files with 15877 additions and 0 deletions

View file

@ -0,0 +1,33 @@
@% = &2040A
MAX_N = 20
TIMES = 1000000
FOR n = 1 TO MAX_N
avg = FNtest(n, TIMES)
theory = FNanalytical(n)
diff = (avg / theory - 1) * 100
PRINT STR$(n), avg, theory, diff "%"
NEXT
END
DEF FNanalytical(n)
LOCAL i, s
FOR i = 1 TO n
s += FNfactorial(n) / n^i / FNfactorial(n-i)
NEXT
= s
DEF FNtest(n, times)
LOCAL i, b, c, x
FOR i = 1 TO times
x = 1 : b = 0
WHILE (b AND x) = 0
c += 1
b OR= x
x = 1 << (RND(n) - 1)
ENDWHILE
NEXT
= c / times
DEF FNfactorial(n)
IF n=1 OR n=0 THEN =1 ELSE = n * FNfactorial(n-1)