Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
44
Task/Fibonacci-word/CLU/fibonacci-word.clu
Normal file
44
Task/Fibonacci-word/CLU/fibonacci-word.clu
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
% NOTE: when compiling with Portable CLU,
|
||||
% this program needs to be merged with 'useful.lib' to get log()
|
||||
%
|
||||
% pclu -merge $CLUHOME/lib/useful.lib -compile fib_words.clu
|
||||
|
||||
% Yield pairs of (zeroes, ones) for each Fibonacci word
|
||||
% We don't generate the whole words, as that would take too much
|
||||
% memory.
|
||||
fib_words = iter () yields (int,int)
|
||||
az: int := 0 ao: int := 1
|
||||
bz: int := 1 bo: int := 0
|
||||
|
||||
while true do
|
||||
yield(az, ao)
|
||||
az, ao, bz, bo := bz, bo, az+bz, ao+bo
|
||||
end
|
||||
end fib_words
|
||||
|
||||
fib_entropy = proc (zeroes, ones: int) returns (real)
|
||||
rsize: real := real$i2r(zeroes + ones)
|
||||
zeroes_frac: real := real$i2r(zeroes)/rsize
|
||||
ones_frac: real := real$i2r(ones)/rsize
|
||||
|
||||
return(-zeroes_frac*log(zeroes_frac)/log(2.0)
|
||||
-ones_frac*log(ones_frac)/log(2.0))
|
||||
except when undefined: return(0.0) end
|
||||
end fib_entropy
|
||||
|
||||
start_up = proc ()
|
||||
max = 37
|
||||
|
||||
po: stream := stream$primary_output()
|
||||
stream$putl(po, " # Length Entropy")
|
||||
|
||||
num: int := 0
|
||||
for zeroes, ones: int in fib_words() do
|
||||
num := num + 1
|
||||
stream$putright(po, int$unparse(num), 2)
|
||||
stream$putright(po, int$unparse(zeroes+ones), 10)
|
||||
stream$putright(po, f_form(fib_entropy(zeroes, ones), 1, 6), 10)
|
||||
stream$putl(po, "")
|
||||
if num=max then break end
|
||||
end
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue