Jump to content

Benford's law: Difference between revisions

m
No edit summary
m (→‎{{header|Sidef}}: updated code)
Line 3,965:
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var (actuals, expected) = ([], [])
var fibonacci = 1000.of {|i| fib(i).digit(0-1) }
 
for i in (1..9) {
var num = fibonacci.count_by {|j| j == i }
actuals.append(num / 1000)
Line 3,974:
 
"%17s%17s\n".printf("Observed","Expected")
 
for i in (1..9) {
"%d : %11s %%%15s %%\n".printf(
i, "%.2f".sprintf(100 * actuals[i - 1]),
Line 3,980 ⟶ 3,981:
)
}</syntaxhighlight>
 
{{out}}
<pre>
Line 3,994:
9 : 4.50 % 4.58 %
</pre>
 
=={{header|SQL}}==
If we load some numbers into a table, we can do the sums without too much difficulty. I tried to make this as database-neutral as possible, but I only had Oracle handy to test it on.
2,747

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.