New answers tagged

0

Python 3, 46 44 bytes lambda n,a=5**.5:((.5+a/2)**n-(.5-a/2)**n)/a Try it online! Uses Binet's formula to derive the nth Fibonacci number. Very wrong answer from me misreading the question: g=lambda n:n+g(n-1)if n else n Try it online!


2

TypeScript's type system, 193 188 186 bytes type L='length' type T<N,U extends 0[]=[]>=U[L]extends N?U:T<N,[...U,0]> type S<A,B>=T<A>extends[...infer U,...T<B>]?U[L]:0 type F<N>=N extends 0|1?N:[...T<F<S<N,1>>>,...T<F<S<N,2>>>][L] There's no way to do I/O here, but we can use hovering ...


1

Pari/GP, 30 bytes f(n)=if(n>0,[f(n-1),f(n-2)],0) Try it online!


1

tinylisp, 46 45 bytes (d F(q((N)(i(l N 1)0(c(F(s N 1))(c(F(s N 2))( Try it online! A function submission that takes an integer and returns a list: The empty tree is represented by 0 A nonempty tree is represented by a two-element list containing its left and right subtrees Ungolfed Recursively implements the definition: if N is less than 1, returns 0; ...


1

Kotlin, 85 71 bytes Thanks to @user, saved 14 bytes fun f(n:Int):Any=when(n){0->"0" 1->"[1]" else->"[${f(n-1)},${f(n-2)}]"} Try it online!


Top 50 recent answers are included