June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,26 +1,27 @@
# Code for "entropy" taken from https://rosettacode.org/wiki/Entropy#Julia
entropy(s::String)::Float32 = -sum(x -> x * log(2, x), [count(x -> x == c, s) / length(s) for c in unique(s)])
using DataStructures
entropy(s::AbstractString) = -sum(x -> x / length(s) * log2(x / length(s)), values(counter(s)))
function fibboword(n::Int64)::Array{String}
# Initialize the result
r = Array{String}(n)
# First element
r[1] = "0"
# If more than 2, set the second element
if (n ≥ 2)
r[2] = "1"
end
# Recursively create elements > 3
for i in 3:n
r[i] = r[i - 1] * r[i - 2]
end
return r
function fibboword(n::Int64)
# Initialize the result
r = Array{String}(n)
# First element
r[1] = "0"
# If more than 2, set the second element
if n ≥ 2 r[2] = "1" end
# Recursively create elements > 3
for i in 3:n
r[i] = r[i - 1] * r[i - 2]
end
return r
end
function testfibbo(n::Int64)
fib = fibboword(n)
for i in 1:length(fib)
println(i, "\t", length(fib[i]), "\t", entropy(fib[i]))
end
return 0
function testfibbo(n::Integer)
fib = fibboword(n)
for i in 1:length(fib)
@printf("%3d%9d%12.6f\n", i, length(fib[i]), entropy(fib[i]))
end
return 0
end
println(" n\tlength\tentropy")
testfibbo(37)