Jump to content

Fibonacci word: Difference between revisions

Added Uiua solution
(Add Dart implementation)
(Added Uiua solution)
Line 4,852:
36 14930352 0.959418728222743 <too long>
37 24157817 0.959418728222745 <too long>
</pre>
 
=={{header|Uiua}}==
Memoisation saves the day :-)
 
<syntaxhighlight lang="Uiua">
# Build the string recursively.
F ← |1 memo⟨⟨⊂∩F-1.-1|"0"◌⟩=2.|"1"◌⟩=1.
# General entropy formula - quite slow for this task.
Egen ← /+(¯×ₙ2.)÷/+.≡(⧻⊚=)⊃◴¤
# Specific entropy formula for a binary string.
E ← ⍥(0◌)=NaN.+∩(¯×ₙ2.)⟜(¯-1)÷⊃⧻(⧻⊚="1")
 
# Much faster approach -- don't even build the string, just count
# how many "0"s and "1"s the string will have.
Fx ← |1 memo⟨⟨+∩Fx-1.-1|[1 0]◌⟩=2.|[0 1]◌⟩=1.
Ex ← ⍥(0◌)=NaN./+(¯×ₙ2.)÷/+.
 
# Print and time it
⍜now(≡(⇌[⊃/+ (⍜(×1e8)⁅Ex)Fx.])+1⇡37)
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ 1 0 1
2 0 1
3 1 2
4 0.91829583 3
5 0.97095059 5
6 0.954434 8
7 0.9612366 13
8 0.95871188 21
9 0.95968689 34
10 0.95931603 55
...etc...
35 0.95941873 9227465
36 0.95941873 14930352
37 0.95941873 24157817
0.0029999999678694-ε
</pre>
 
102

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.