rosetta code: also add fibonacci_word
authorJean Privat <jean@pryen.org>
Fri, 10 Jul 2015 15:59:29 +0000 (11:59 -0400)
committerJean Privat <jean@pryen.org>
Fri, 10 Jul 2015 15:59:29 +0000 (11:59 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

examples/rosettacode/fibonacci_word.nit [new file with mode: 0644]
tests/niti.skip
tests/nitvm.skip
tests/sav/fibonacci_word.res [new file with mode: 0644]

diff --git a/examples/rosettacode/fibonacci_word.nit b/examples/rosettacode/fibonacci_word.nit
new file mode 100644 (file)
index 0000000..fec4929
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Fibonacci_word
+# SEE: <http://rosettacode.org/wiki/Fibonacci_word>
+module fibonacci_word
+
+import counter
+
+var words = new Array[String]
+words[0] = ""
+words[1] = "1"
+words[2] = "0"
+
+for i in [1..37] do
+       var w
+       if i >= words.length then
+               w = words[i-1] + words[i-2]
+               words[i] = w
+       else
+               w = words[i]
+       end
+       var out = w
+       if w.length > 40 then out = "..."
+       print "{i}\t{w.length}\t{w.chars.to_counter.entropy.to_precision(16)}\t{out}"
+end
index 0da465e..5c4ff8a 100644 (file)
@@ -27,3 +27,4 @@ mpi_simple
 blink
 input
 first_letter_last_letter
+fibonacci_word
index 0da465e..5c4ff8a 100644 (file)
@@ -27,3 +27,4 @@ mpi_simple
 blink
 input
 first_letter_last_letter
+fibonacci_word
diff --git a/tests/sav/fibonacci_word.res b/tests/sav/fibonacci_word.res
new file mode 100644 (file)
index 0000000..38a9498
--- /dev/null
@@ -0,0 +1,37 @@
+1      1       0.0000000000000000      1
+2      1       0.0000000000000000      0
+3      2       1.0000000000000000      01
+4      3       0.9182958340544894      010
+5      5       0.9709505944546686      01001
+6      8       0.9544340029249650      01001010
+7      13      0.9612366047228760      0100101001001
+8      21      0.9587118829771316      010010100100101001010
+9      34      0.9596868937742170      0100101001001010010100100101001001
+10     55      0.9593160320543778      ...
+11     89      0.9594579158386696      ...
+12     144     0.9594037542210228      ...
+13     233     0.9594244469559864      ...
+14     377     0.9594165437404406      ...
+15     610     0.9594195626031440      ...
+16     987     0.9594184095152248      ...
+17     1597    0.9594188499578102      ...
+18     2584    0.9594186817240320      ...
+19     4181    0.9594187459836638      ...
+20     6765    0.9594187214386752      ...
+21     10946   0.9594187308140276      ...
+22     17711   0.9594187272329618      ...
+23     28657   0.9594187286008076      ...
+24     46368   0.9594187280783368      ...
+25     75025   0.9594187282779028      ...
+26     121393  0.9594187282016752      ...
+27     196418  0.9594187282307916      ...
+28     317811  0.9594187282196702      ...
+29     514229  0.9594187282239182      ...
+30     832040  0.9594187282222962      ...
+31     1346269 0.9594187282229156      ...
+32     2178309 0.9594187282226794      ...
+33     3524578 0.9594187282227690      ...
+34     5702887 0.9594187282227344      ...
+35     9227465 0.9594187282227478      ...
+36     14930352        0.9594187282227430      ...
+37     24157817        0.9594187282227448      ...