Benford's law: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Sidef}}: updated code) |
||
Line 3,965: | Line 3,965: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">var (actuals, expected) = ([], []) |
<syntaxhighlight lang="ruby">var (actuals, expected) = ([], []) |
||
var fibonacci = 1000.of {|i| fib(i).digit( |
var fibonacci = 1000.of {|i| fib(i).digit(-1) } |
||
for i (1..9) { |
for i in (1..9) { |
||
var num = fibonacci.count_by {|j| j == i } |
var num = fibonacci.count_by {|j| j == i } |
||
actuals.append(num / 1000) |
actuals.append(num / 1000) |
||
Line 3,974: | Line 3,974: | ||
"%17s%17s\n".printf("Observed","Expected") |
"%17s%17s\n".printf("Observed","Expected") |
||
for i (1..9) { |
for i in (1..9) { |
||
"%d : %11s %%%15s %%\n".printf( |
"%d : %11s %%%15s %%\n".printf( |
||
i, "%.2f".sprintf(100 * actuals[i - 1]), |
i, "%.2f".sprintf(100 * actuals[i - 1]), |
||
Line 3,980: | Line 3,981: | ||
) |
) |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,994: | Line 3,994: | ||
9 : 4.50 % 4.58 % |
9 : 4.50 % 4.58 % |
||
</pre> |
</pre> |
||
=={{header|SQL}}== |
=={{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. |
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. |