Benford's law: Difference between revisions
m
→{{header|Julia}}
Line 1,979:
χ² = 3204.8072</pre>
=={{header|Julia}}==
<syntaxhighlight lang="julia">
struct Fib end
Base.iterate(::Fib, (a, b) = (big(
Base.eltype(::Type{Fib}) = BigInt
Base.IteratorSize(::Type{Fib}) = Base.IsInfinite()
function benford(list)▼
counts = zeros(Int, 9)
countdigit(n) = counts[firstdigit(n)] += 1
foreach(countdigit, list)
counts ./ sum(counts)
end
# Benford's law
▲P(d) = log10(1 + 1 / d)
▲function benford(list)
▲benford(fib(1000))</syntaxhighlight>
{{Out}}
<pre>9×3 Matrix{Real}:
1 0.301 0.30103
2 0.177 0.176091
=={{header|Kotlin}}==
|