2026-02-01 16:33:20 -08:00
|
|
|
fastfunc average n reps .
|
|
|
|
|
len f[] n
|
|
|
|
|
len seen[] n
|
2024-04-19 16:56:29 -07:00
|
|
|
for r to reps
|
2026-02-01 16:33:20 -08:00
|
|
|
for i = 1 to n
|
2026-04-30 12:34:36 -04:00
|
|
|
f[i] = random 1 n
|
2026-02-01 16:33:20 -08:00
|
|
|
seen[i] = 0
|
|
|
|
|
.
|
2024-04-19 16:56:29 -07:00
|
|
|
x = 1
|
|
|
|
|
while seen[x] = 0
|
|
|
|
|
seen[x] = 1
|
|
|
|
|
x = f[x]
|
|
|
|
|
count += 1
|
|
|
|
|
.
|
|
|
|
|
.
|
|
|
|
|
return count / reps
|
|
|
|
|
.
|
2026-02-01 16:33:20 -08:00
|
|
|
fastfunc analytical n .
|
2024-04-19 16:56:29 -07:00
|
|
|
s = 1
|
|
|
|
|
t = 1
|
|
|
|
|
for i = n - 1 downto 1
|
|
|
|
|
t = t * i / n
|
|
|
|
|
s += t
|
|
|
|
|
.
|
|
|
|
|
return s
|
|
|
|
|
.
|
|
|
|
|
print " N average analytical (error)"
|
|
|
|
|
print "=== ======= ========== ======="
|
|
|
|
|
for n to 20
|
|
|
|
|
avg = average n 1e6
|
|
|
|
|
ana = analytical n
|
|
|
|
|
err = (avg - ana) / ana * 100
|
2025-06-11 20:16:52 -04:00
|
|
|
numfmt 2 0
|
2024-04-19 16:56:29 -07:00
|
|
|
write n
|
2025-06-11 20:16:52 -04:00
|
|
|
numfmt 9 4
|
2024-04-19 16:56:29 -07:00
|
|
|
print avg & ana & err & "%"
|
|
|
|
|
.
|