J,24 14字节
#.~2+&%&1~#-#\
在线尝试!
深入研究了使用斐波那契混合基数的24字节版本。
怎么运行的
#.~2+&%&1~#-#\ Example input: y=1 0 0 1 0
#-#\ Length minus 1-based indices; 4 3 2 1 0
2 ~ Starting from 2, run the following (4,3,2,1,0) times:
+&%&1 Given y, compute 1 + 1 / y
The result is 13/8 8/5 5/3 3/2 2
#.~ Mixed base conversion of y into base above; 2+8=10
J,21字节
1#.|.*[:+/@(!~#-])\#\
在线尝试!
Galen Ivanov的25字节解决方案的改进版。
使用帕斯卡三角形的对角线总和,它等于二项式系数的总和:
Fñ= ∑我= 0ññ - 我C一世
怎么运行的
1#.|.*[:+/@(!~#-])\#\
Example input: 1 0 0 1 0
#\ Generate 1-based index; 1 2 3 4 5
[: \ For each prefix of above... (ex. 1 2 3)
#-] Subtract each element from the length (ex. 2 1 0)
(!~ ) Compute binomial coefficient (ex. 3C0 + 2C1 + 1C2)
+/@ Sum
The result is Fibonacci numbers; 1 2 3 5 8
|.* Multiply with mirrored self; 0 2 0 0 8
1#. Sum; 10
J,24个字节
3 :'y#.~|.(1+%)^:(<#y)2'
在线尝试!
单子词显式动词。生成代表Fibonacci基准的混合基准,然后将其输入基准转换#.
。
怎么运行的
y#.~|.(1+%)^:(<#y)2 Explicit verb, input: y = Fibonacci digit array, n = length of y
(1+%) x -> 1 + 1/x
^:(<#y)2 Apply the above 0..n-1 times to 2
The result looks like 2/1, 3/2, 5/3, 8/5, 13/8, ...
|. Reverse
Now, if it is fed into #. on the left, the digit values become
...(8/5 * 5/3 * 3/2 * 2/1), (5/3 * 3/2 * 2/1), (3/2 * 2/1), 2/1, 1
which is ... 8 5 3 2 1 (Yes, it's Fibonacci.)
y#.~ Convert y to a number using Fibonacci base
备择方案
J,27个字节
}.@(+#{.3#{.)^:(<:@#)@(,&0)
在线尝试!
这个想法:
1 0 0 1 0 1
-1 +1 +1
------------------
1 1 1 0 1
-1 +1 +1
------------------
2 2 0 1
-2 +2 +2
------------------
4 2 1
-4 +4 +4
------------------
6 5
-6 +6 +6 <- Add an imaginary digit that has value 1
---------------------
11 6
-11+11
---------------------
17 <- the answer
J,30个字节
0.5<.@+(%:5)%~(-:>:%:5)#.,&0 0
在线尝试!
这是花了最大的力气建造的。使用带舍入技巧的闭式表达式。在表达式中,第0个和第1个值分别为0和1,因此实际的数字幂必须以2开头。
0.5<.@+(%:5)%~(-:>:%:5)#.,&0 0 Tacit verb.
,&0 0 Add two zeroes at the end
(-:>:%:5)#. Convert to a number using base phi (golden ratio)
(%:5)%~ Divide by sqrt(5)
0.5<.@+ Round to nearest integer
尽管误差(((1-sqrt(5))/2)^n
项)可能会累积,但永远不会超过0.5,因此舍入技巧会达到无穷大。数学上:
最大(| e r r o r |)= 15√∑1个∞(1 - 5√2)2 n= 15√∑0∞(1 - 5√2)ñ= 5√− 12 5√< 12