Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
53
Task/Fibonacci-word/Seed7/fibonacci-word.seed7
Normal file
53
Task/Fibonacci-word/Seed7/fibonacci-word.seed7
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "float.s7i";
|
||||
include "math.s7i";
|
||||
|
||||
const func float: entropy (in string: stri) is func
|
||||
result
|
||||
var float: entropy is 0.0;
|
||||
local
|
||||
var hash [char] integer: count is (hash [char] integer).value;
|
||||
var char: ch is ' ';
|
||||
var float: p is 0.0;
|
||||
begin
|
||||
for ch range stri do
|
||||
if ch in count then
|
||||
incr(count[ch]);
|
||||
else
|
||||
count @:= [ch] 1;
|
||||
end if;
|
||||
end for;
|
||||
for key ch range count do
|
||||
p := flt(count[ch]) / flt(length(stri));
|
||||
entropy -:= p * log(p) / log(2.0);
|
||||
end for;
|
||||
end func ;
|
||||
|
||||
const func string: fibWord (in integer: number) is func
|
||||
result
|
||||
var string: fibWord is "1";
|
||||
local
|
||||
var integer: i is 0;
|
||||
var string: a is "1";
|
||||
var string: c is "";
|
||||
begin
|
||||
if number >= 2 then
|
||||
fibWord := "0";
|
||||
for i range 3 to number do
|
||||
c := a;
|
||||
a := fibWord;
|
||||
fibWord &:= c;
|
||||
end for;
|
||||
end if;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var integer: index is 0;
|
||||
var string: fibWord is "";
|
||||
begin
|
||||
for index range 1 to 37 do
|
||||
fibWord := fibWord(index);
|
||||
writeln(index lpad 2 <& length(fibWord) lpad 10 <& " " <& entropy(fibWord) digits 15);
|
||||
end for;
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue