Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
36
Task/Fibonacci-word/Forth/fibonacci-word.fth
Normal file
36
Task/Fibonacci-word/Forth/fibonacci-word.fth
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
: .fibword ( n -- )
|
||||
dup case
|
||||
0 of drop ." 1" endof
|
||||
1 of drop ." 0" endof
|
||||
dup 1- recurse
|
||||
2 - recurse
|
||||
endcase ;
|
||||
|
||||
fvariable ilog2
|
||||
1e 2e fln f/ ilog2 f!
|
||||
|
||||
: flog2 ( r -- r )
|
||||
fdup f0<> if
|
||||
fln ilog2 f@ f*
|
||||
then ;
|
||||
|
||||
: entropy ( n1 n2 -- r )
|
||||
2dup + s>f s>f fover f/ fswap s>f fswap f/
|
||||
fdup flog2 f* fswap fdup flog2 f* f+
|
||||
fnegate ;
|
||||
|
||||
: main
|
||||
." N Length Entropy Word" cr
|
||||
1 0
|
||||
37 0 do
|
||||
i 1+ 2 .r
|
||||
2dup + 10 .r space
|
||||
2dup entropy 17 15 1 f.rdp space
|
||||
i 9 < if i .fibword else ." ..." then
|
||||
cr
|
||||
tuck +
|
||||
loop
|
||||
2drop ;
|
||||
|
||||
main
|
||||
bye
|
||||
69
Task/Fibonacci-word/FutureBasic/fibonacci-word.basic
Normal file
69
Task/Fibonacci-word/FutureBasic/fibonacci-word.basic
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
begin globals
|
||||
CFStringRef cur, nex
|
||||
end globals
|
||||
|
||||
|
||||
CFStringRef local fn Increment
|
||||
CFStringRef ret = cur
|
||||
cur = nex
|
||||
nex = fn StringWithFormat( @"%@%@", ret, nex )
|
||||
end fn = ret
|
||||
|
||||
double local fn GetEntropy( s as CFArrayRef )
|
||||
double entropy = 0.0
|
||||
double hist(256)
|
||||
NSUInteger i
|
||||
|
||||
for i = 0 to 255
|
||||
hist(i)= 0
|
||||
next
|
||||
|
||||
for CFNumberRef num in s
|
||||
hist( fn NumberIntegerValue(num) ) += 1
|
||||
next
|
||||
|
||||
for i = 0 to 255
|
||||
if ( hist(i) > 0 )
|
||||
double rat = hist(i) / fn ArrayCount( s )
|
||||
entropy -= rat * log2(rat)
|
||||
end if
|
||||
next
|
||||
return entropy
|
||||
end fn = 0.0
|
||||
|
||||
CFStringRef local fn ReverseString( string as CFStringRef )
|
||||
CFMutableStringRef reversedStr = fn MutableStringNew
|
||||
for NSInteger i = len(string) - 1 to 0 step -1
|
||||
MutableStringAppendString( reversedStr, fn StringWithFormat( @"%c", fn StringCharacterAtIndex( string, i ) ) )
|
||||
next
|
||||
end fn = reversedStr
|
||||
|
||||
local fn DoIt
|
||||
cur = @"1"
|
||||
nex = @"0"
|
||||
|
||||
NSLog( @"%5s %10s %11s %33s", "No.", "Length", "Entrophy", "Binary Fibonacci Word" )
|
||||
CFTimeInterval t = fn CACurrentMediaTime
|
||||
for int i = 0 to 36
|
||||
CFStringRef string = fn Increment
|
||||
CFMutableArrayRef asciiValues = fn MutableArrayNew
|
||||
for NSUInteger j = 0 to len(string) - 1
|
||||
unichar character = fn StringCharacterAtIndex( string, j )
|
||||
MutableArrayAddObject( asciiValues, @(character) )
|
||||
next
|
||||
double ent = fn GetEntropy( asciiValues )
|
||||
|
||||
if ( i <= 10 )
|
||||
NSLog( @"%3d. %9lu %19.15f %@", i+1, (unsigned long)len(string), ent, fn ReverseString( string ) )
|
||||
else
|
||||
NSLog( @"%3d. %9lu %19.15f [length exceeds task limits]", i+1, (unsigned long)len(string), ent )
|
||||
end if
|
||||
next
|
||||
NSLog( @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t) * 1000 )
|
||||
end fn
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue