# Tag Info

1

R, 100 bytes h=function(n,m=1,l=0,p=.5+5^.5/2)if(n>1,h(n-1,m+l,m),{r=m/l while(r%/%10^-T==p%/%10^-T)T=T+1 T-1}) Try it online! Gets the ratio of the nth and n-1th fibonacci numbers using the recursive function: g=function(n,m=1,l=0)if(n,g(n-1,m+l,m),m/l) Then calculates the number of digits of the ratio that are shared with phi by comparing ...

0

05AB1E, 17 bytes 3LÍ+ÅfRü/ø€ËÅγнÍ Try it online! 3L push the list [1,2,3] Í subtract 2, [-1,0,1] + add to the implicit input, [9, 10, 11] Åf take the nth Fibonacci number, [34, 55, 89] R reverse, [89, 55, 34] ü/ take the division of each pair, [1.6181818181818182, 1.6176470588235294]  dump to stack ø zip, ["11", &...

3

Desmos, 169 113 107 bytes s=.5 p=s+s5^s F(n)=p^n-(1-p)^n h(k,n)=floor(10^{[1...n]}k) f(n)=total(1-abs(sign(h(p,n)-h(F(n)/F(n-1),n)))) Try It On Desmos! Try It On Desmos! - Prettified Test the code on function $f(n)$. As usual, Desmos is in last place :|. Probably can be golfed more though. Brief Explanation: s=.5: Makes a variable $s$ that has a value ...

1

Raku, 45 bytes {first :k,?*,(@($/=.words)Z-($0,$1,*+*...*))} Try it online!$/ = .words stores the words (numbers) of the input string into the pattern-match variable $/. Conveniently, the elements of that variable can be accessed with$0, $1, etc, so$0, $1, * + * ... * forms the Fibonacci sequence starting with the first two input numbers. The input ... 0 Husk, 5 bytes δV≠İf Try it online! You know it's a good day when you get to use decorV in an answer. 0 Pxem, Numeric: 34 bytes + Non-numeric: 21 bytes = 55 bytes. Filename: Hello world!!!.pxxxxx1234567890123456789012345678901234 Content: empty The boring answer. The stupid latter part is nothing but a garbage. Try it online! 0 Pxem, 0 bytes (content) + 52 bytes (filename). Filename (escaped): \002._._X.w.c.t.v.m.v.+._.c.t.v.m.v.-\001.r.x.n.d.a\001.+.vX.a Usage From stdin Must be an actual FIBonacci sequence Each integer are separated with blank characters With comments XX.z # Initial stack: F(i-1), F(i-2), i # i is initially 2 .a\002._._XX.z # while :; do .aX.wXX.z # to: (F(... 1 Pip -s, 22 bytes Y^1LaS(l+:Py)+:RVlPE0y Outputs the first n rows. Try it online! Explanation Each row of the triangle, represented as a list, can be obtained by a two-step process: first add the two previous rows; then take that result, reverse it, prepend 0, and add it to itself. [2 2 2] +[3 5 5 3] ---------- [5 7 7 3] +[0 3 7 7 5] ------------ [5 10 14 ... 1 Julia 0.7, 68 65 bytes !n=φ^n-(1-φ)^n >(n,x=1)=!n/!(n-1)*10^x÷1!=φ*10^x÷1?x-1:n>x+1 Try it online! Fibonacci numbers are calculated using Binet's formula dropping the constant $\sqrt5$ term in the denominator since we are interested in ratios anyway. Thanks to MarcMush for -3 bytes. 0 Charcoal, 39 bytes ＮθＦ²⊞υιＦ⊖θ⊞υΣ…⮌υ²Ｉ⊖⊖⌕ＥＩ∕⊟υ⊟υ¬⁻ι§Ｉ⊘⊕₂⁵κ⁰ Try it online! Only works up to n=40 due to floating-point rounding. Explanation: Ｎθ Input n. Ｆ²⊞υιＦ⊖θ⊞υΣ…⮌υ² Calculate the first n Fibonacci numbers. Ｉ⊖⊖⌕ＥＩ∕⊟υ⊟υ¬⁻ι§Ｉ⊘⊕₂⁵κ⁰ Divide the last two and compare the string representation with that of φ. 87 bytes for arbitrary precision: ＮθＦ²⊞υιＦ⊖θ⊞υΣ…⮌... 2 Python 3, 120 102 88 bytes Saved a whopping 18 32 bytes thanks to ovs!!! f=lambda n,r=1,a=0,b=1:n>1and f(n-1,r,b,a+b)or-((1+5**.5)*r//2!=b*r//a or~f(n,r*10,a,b)) Try it online! 6 Haskell, 76 75 bytes g n=last[i|i<-[1..n],i?n==i?99] e?n=floor$10^e*f!!n/f!!(n-1) f=0:scanl(+)1f Try it online! The relevant function is g, which takes n as input and returns the number of matching decimal digits between $\varphi$ and $F_n/F_{n-1}$. It probably won't work if the answer is larger than 15 because that's the maximum precision allowed ...

9

JavaScript (ES7),  77 75 69  67 bytes n=>(g=p=>--n>1?g(q,q+=p):(1+5**.5)/2*(m*=10)^q/p*m?0:1+g(p))(q=m=1) Try it online! Commented n => ( // main function, taking n g = p => // g is a recursive function taking p which, along with q, // is used to compute the Fibonacci sequence --n > 1 ? // ...

5

APL (Dyalog Extended), 37 32 bytes Full program, assumes ⎕IO←0. -5 bytes by not using dfns.fibonacci. 0⍳⍨2↓=⌿↑⍕¨(÷/(+/,⊃)⍣⎕⍳2),2÷⍨1+√5 Try it online! (+/,⊃)⍣⎕⍳2 calculates adjacent fibonacci pairs. Starting with 0 1 ≡ ⍳2, iterate input (⎕) times: pair the sum of both values +/ with the first value ⊃. 2÷⍨1+√5 ⍝ Phi , ⍝ paired ...

4

Jelly, 17 bytes ,’ÆḞ÷/Ṿ=ØpṾ¤ŒɠḢ_2 Try it online! Probably can be improved. Explanation ,’ÆḞ÷/Ṿ=ØpṾ¤ŒɠḢ_2 Main monadic link , Pair with ’ n-1 ÆḞ Get the Fibonacci numbers / Reduce by ÷ division Ṿ Convert to string = Equals [...

3

JavaScript, 97 89 bytes n=>[...''+(f=n=>n<2?n:f(n-1)+f(n-2))(n)/f(n-1)].findIndex((e,i)=>${.5+5**.5/2}[i]!=e)-2 You have got to be kidding me. Not the best answer definitely but uses a different approach. Also, try it online. 8 bytes were shaved off the program thanks to suggestions from the OP as well as a rule change. 3 Husk, 17 15 bytes :;1mSż+oΘ↔Ẋż+Θ₀ Try it online! Answering Razetime's challenge from the Husk chat Explanation :;1mSż+oΘ↔Ẋż+Θ₀ :;1 Begin with [1] ₀ Define the sequence recursively Ẋż+Θ Pairwise sums of rows (e.g. [1,1]+[2,2,2]=[3,3,2]) m For each of these sums Sż+ Sum it to ... 2 Haskell, 59 bytes x!y=zipWith(+)x$y++[0,0] x#y=x:(0:0:y)!y!(0:x)!x#x t=[1]#[] Try it online!

2

Husk, 29 28 23 19 bytes Saved 1 byte thanks to caird coinheringaahing Saved 5 bytes thanks to Razetime! Saved 4 bytes thanks to Leo! ¡öFz+S+m↔z+ḣ´e0↔;;1 Try it online! Outputs an infinite list, explanation coming soon. This is really long, so it looks like I'm not going to get the bounty anyway. ¡öFz+S+m↔z+ḣ´e0↔;;1 ¡ Create infinite ...

2

Pinecone, 35 bytes b:0;a:1;tru@(print:a;t:a;a:a+b;b:t) Competitive Pinecone answer!

2

Python 3, 191 143 bytes* from itertools import* s=lambda n:[l for l in product(*[range(1,9**9**n)]*9**9**n)if all(l[l[i]]+l[l[i+1]]==l[l[i+2]]for i in range(n))][0][:n] The function s takes an integer n and returns a tuple of length n which starts with (1, 1, 2, 3, 6, ...). This is simple brute force, and is practically infeasible for even n=2. To make ...

5

JavaScript (ES6),  181  171 bytes This is really just a port of @hyper-neutrino's answer. Returns the $n$th term of the sequence. n=>(s=new Set(k=[A=n=>s.has(++n)?A(n):s.add(n)|n,1,2,3]),h=(x,y)=>x>n?k[n]:(g=(x,y)=>x>n+1&y>n+1?h(A,A):g(y,k[k[s.add(x)|x]=y]=(F=p=>x--?F(q,q+=p):p)(q=1)))(x,y))(4,6) Try it online! Commented ...

6

Haskell, 181 149 bytes 1:2:3:4#(0:1:z) n#(0:x:y:t)|x<1=n#((n+1):f!!n:y:t)|m<-n+2=n#(m:x:f!!n:t) n#(x:t)|(a,_:b)<-splitAt(f!!n-n-1)t=x:(n+1)#(a++f!!x:b) f=1:scanl(+)1f z=0:z Try it online! The infinite (1-indexed) sequence (it breaks after the 33rd element because of integer overflow, but the algorithm should in principle work for arbitrarily large ...

4

Haskell, 34 bytes data T=E|N T T f=E:scanl N(N E E)f Try it online! f is the infinite list of Fibonacci trees, represented as a custom type defined in the first line (E is the empty tree, N l r is the tree with left subtree l and right subtree r). How? Haskell is usually very well-suited for Fibonacci-related tasks. Assume we have a recurrence of the form \$...

13

Python 2, 226 bytes g=input()+2 f=lambda n,x=1,y=1:n and f(n-1,y,x+y)or x k={1:1,2:2,3:3} s=set(k) x=4 y=6 while g/x: while g/x|g/y:k[y]=f(x);k[x]=y;s|={x};x,y=y,f(x) x,y=sorted(set(range(1,max(s)+3))-s)[:2];s|={y} print map(k.get,range(1,g-1)) Try it online! -33 bytes thanks to ovs

2

Branch, 35 bytes /;{^\;{Z[{Z0]z^[/@^\@^0]~LLn[0`P] Try it on the online Branch interpreter! Of course, it's only natural that a language based on binary trees would have a way to solve this challenge. Branch is still in development; I'm not sure how I could've solved this before adding a bunch of bugfixes and a couple of new helpers. Pretty-printing the ...

2

APL(Dyalog Unicode), 14 bytes SBCS {⍵>0:∇¨⍵-⍳2⋄0} Try it on APLgolf! Outputs as a nested list, where each list contains two elements which are the left and right children, and 0 is null. -10 bytes thanks to Razetime and user, and also using a better online interface courtesy of Razetime Explanation { } dfn ⍵>0: if the argument ...

Top 50 recent answers are included