44
\$\begingroup\$

Definition

Fibonacci sequence F(n), on the positive integers, are defined as such:

1. F(1) = 1
2. F(2) = 1
3. F(n) = F(n-1) + F(n-2), where n is an integer and n > 2

The Fibonacci-orial of a positive integer is the product of [F(1), F(2), ..., F(n)].

Task

Given positive integer n, find the Fibonacci-orial of n.

Specs

The fibonacci-orial of 100 must compute in under 5 seconds on a reasonable computer.

Testcases

n   Fibonacci-orial of n
1   1
2   1
3   2
4   6
5   30
6   240
7   3120
8   65520
9   2227680
10  122522400
11  10904493600
12  1570247078400
13  365867569267200
14  137932073613734400
15  84138564904377984000
16  83044763560621070208000
17  132622487406311849122176000
18  342696507457909818131702784000
19  1432814097681520949608649339904000
20  9692987370815489224102512784450560000
100 3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000

References

\$\endgroup\$
13
  • \$\begingroup\$ Related. \$\endgroup\$
    – Leaky Nun
    Jul 30, 2016 at 3:19
  • 2
    \$\begingroup\$ @LuisMendo The sum of fibonacci is... you've guessed it, fibonacci. Well, minus one. \$\endgroup\$
    – Leaky Nun
    Jul 30, 2016 at 9:23
  • 2
    \$\begingroup\$ @LeakyNun Currently the JavaScript answer only completes the test cases up to 15 because JavaScript cannot correctly compare (or manipulate) numbers beyond 2^53 - 1. This is most likely similar for a lot of the submissions here, because most languages don't support numbers that big \$\endgroup\$
    – bren
    Jul 30, 2016 at 13:54
  • 1
    \$\begingroup\$ What do you mean by "reasonable computer"? \$\endgroup\$ Jul 31, 2016 at 16:26
  • 3
    \$\begingroup\$ -1 because this seems like several challenges tacked together (range, fibonacci of each, factorial) with no particularly interesting shortcuts. \$\endgroup\$ Dec 28, 2017 at 2:25

69 Answers 69

1 2
3
0
\$\begingroup\$

Jelly, 4 bytes

RÆḞP

Try it online!

Explanation

R       inclusive range
 ÆḞ     nth fibonacci number
   P    product
\$\endgroup\$
0
\$\begingroup\$

Japt, 7 bytes

õ@MgXÃ×

Try it


Explanation

õ         :Range [1,input]
 @   Ã    :Pass each X through a function
  MgX     :  Xth Fibonacci number
      ×   :Reduce by multiplication
\$\endgroup\$
0
\$\begingroup\$

Common Lisp, 65 bytes

(defun f(n &optional(a 1)(b 1))(if(< n 1)1(*(f(1- n)b(+ a b))a)))

Try it online!

Another port of Dennis's Python answer.

The straight iterative implementation is four bytes more:

(lambda(n)(do((x 1 y)(y 1(+ x y))(i 0(1+ i))(p 1(* p x)))((= i n)p)))
\$\endgroup\$
0
\$\begingroup\$

Stax, 5 bytes

Æn─⌂▄

Run and debug it Unpacked it's

vOF|5*
v      decrement input by 1
 O     tuck 1 under top value of stack (in case input was one)
  F    turns rest of loop into a for loop for 1..(input-1)
   |5  get F(i+1)
     * multiply by running product
\$\endgroup\$
0
\$\begingroup\$

Lua, 76 bytes

Naïve solution (works until 14)

Try it online!

function I(x,a,b,c)return x<1 and c or I(x-1,a+b,a,a*c)end print(I(z,1,0,1))

Arbitrary-precision solution, using lua-nums (94 bytes)

--nums.bn is the name of the library as obtained from Luarocks
function I(x,a,b,c)return x<1 and c or I(x-1,a+b,require"nums.bn"(a),a*c)end print(I(z,1,0,1))

(Obviously you could rename the library in order to have shorter code, but this smells like cheating).

Timings for the second solution are:

real    0m0,030s
user    0m0,028s
sys 0m0,000s
\$\endgroup\$
0
\$\begingroup\$

Javascript, 44 bytes

n=>eval(`for(c=a=b=1;--n;b+=t)t=a,c*=a=b;c`)

based on this Fibbonaci sequence

\$\endgroup\$
1
  • \$\begingroup\$ i think you can remove the brackets after eval? \$\endgroup\$
    – Razetime
    May 19, 2021 at 3:09
0
\$\begingroup\$

Charcoal, 28 bytes

≔¹α≔¹β≔¹χFN«≔×χαχ≔βα≔⁺αββ»Iχ

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Factor + math.unicode, 43 bytes

[ 0 1 rot 1 - [ tuck + dup ] replicate Π ]

Try it online!

\$\endgroup\$
0
\$\begingroup\$

MathGolf, 4 bytes

╒fε*

Try it online.

Explanation:

╒     # Push a list in the range [1, (implicit) input]
 f    # Convert each to its Fibonacci value
  ε*  # Get the product of this list; reduce by multiplication
      # (after which the entire stack is output implicitly as result)
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.