Fibonacci-orial

35

8

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

Leaky Nun

Posted 2016-07-30T03:19:28.737

Reputation: 45 011

Related. – Leaky Nun – 2016-07-30T03:19:39.707

@Dennis 1. So it took half a second to import them and your program finished in half a second? 2. Yes. 3. Just let it overflow – Leaky Nun – 2016-07-30T03:48:05.923

Can F(100) return Infinity if our language cannot handle numbers that large? – MayorMonty – 2016-07-30T07:46:27.900

@MayorMonty I would say no, but that would invalidate an existing answer. – Leaky Nun – 2016-07-30T07:53:41.150

The issues in the above comments could probably have been solved by asking for the Fibonacci-sum instead of the the Fibonacci-orial. Besides, there's some chance that Mathematica doesn't have a builtin for that :-P – Luis Mendo – 2016-07-30T09:19:04.990

1@LuisMendo The sum of fibonacci is... you've guessed it, fibonacci. Well, minus one. – Leaky Nun – 2016-07-30T09:23:26.930

@LeakyNun Oh, I hadn't thought about that – Luis Mendo – 2016-07-30T09:50:16.723

@downvoter: can you tell me how I can make this challenge better? – Leaky Nun – 2016-07-30T13:22:00.593

2@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 – MayorMonty – 2016-07-30T13:54:41.243

1What do you mean by "reasonable computer"? – Erik the Outgolfer – 2016-07-31T16:26:22.950

2-1 because this seems like several challenges tacked together (range, fibonacci of each, factorial) with no particularly interesting shortcuts. – Esolanging Fruit – 2017-12-28T02:25:11.743

Can this be 0 indexed? – FantaC – 2018-02-19T03:16:11.730

@tfbninja sure, why not – Leaky Nun – 2018-02-19T12:05:07.253

Answers

63

Mathematica, 10 bytes

Fibonorial

Another Mathematica built-in soundly beaten by a golfing language without the built-in.

Martin Ender

Posted 2016-07-30T03:19:28.737

Reputation: 184 808

49I… w-what… why, Mathematica?! – Lynn – 2016-07-30T10:41:55.593

3Forgot that function even existed! – LegionMammal978 – 2016-07-30T13:42:17.013

3

@Lynn Rule 35: If it exists, there's a Mathematica function of it ;)

– Beta Decay – 2016-08-03T15:27:08.340

9

@BetaDecay I thought we had established that it's Rule 110.

– Martin Ender – 2016-08-03T15:29:18.440

1

No, Rule 110 is something very different. Though I'm sure Mathematica has a built-in for that, too.

– AdmBorkBork – 2016-08-05T19:05:48.463

@TimmyD took long enough for someone to get the reference. ;) – Martin Ender – 2016-08-05T19:06:29.033

27

Jelly, 6 bytes

+С1ḊP

Input 100 finishes in 500 ms locally. Try it online!

How it works

+С1ḊP  Niladic link. No input.
        Since the link doesn't start with a nilad, the argument 0 is used.

   1    Yield 1.
+       Add the left and right argument.
 С     Read a number n from STDIN.
        Repeatedly call the dyadic link +, updating the right argument with
        the value of the left one, and the left one with the return value.
        Collect all values of the left argument into an array.
    Ḋ   Dequeue; discard the first Fibonacci number (0).
     P  Product; multiply the remaining ones.

Dennis

Posted 2016-07-30T03:19:28.737

Reputation: 196 637

So is +¡1 a non-built in nth fibonacci and +С1 is the first n Fibonacci numbers? – caird coinheringaahing – 2017-10-11T22:02:38.590

@cairdcoinheringaahing Pretty much. – Dennis – 2017-10-11T22:03:54.523

I thought there was a built-in fibonacci function? – MilkyWay90 – 2019-03-17T17:20:55.190

21

Actually, 4 bytes

Runs the input 100 within 0.2 seconds. Code:

R♂Fπ

Explanation:

R     # Get the range [1, ..., input].
 ♂F   # Map over the array with the fibonacci command.
   π  # Take the product.

Uses the CP-437 encoding. Try it online!.

Adnan

Posted 2016-07-30T03:19:28.737

Reputation: 41 965

1

This is the right tool for the job :) Thanks to some improvements to the Fibonacci function that Leaky Nun made a while back, the 100 test case runs in 0.1 seconds on TIO.

– Mego – 2016-08-01T02:27:38.287

16

Brainfuck, 1198 1067 817 770 741 657 611 603

,[>++++++[-<-------->]<<[->++++++++++<]>>,]>+>+>>+>+<<<<<<[->>>[[-]
<[->+<]>>[-<+<+>>]<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->
[-]>>>>>>+>+<<<<<<<<[->+<]]]]]]]]]]]+>>>>>>>>]<<<<<<<<[->[-<+<<+>>>
]<[->+<]>>>[<<<<<[->>>>>>>>+<<<<<<<<]>>>>>>>>>>>>>]<<<<<<<<[->>>[-<
<<<<<<<+>>>>[->+>>+<<<]>[-<+>]>>>]<<[->>>>>>>+>+<<<<<<<<]<+<<<<<<<<
]>>>[-]>>>>>[[-]>[->+<]>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<
+>[->>>>>>+>+<<<<<<<<[-]]]]]]]]]]>]<<[<]+>>>>>>>>]<<<<<<<<[<<<<<<<<
]>>>>>[>>>>>>>>]+<<<<<<<<]>>>>>>>>>>>[<[-]>>[-<<+>>]>>>>>>>]<<<<<<<
<[<<<<<<<<]>>]>>>>>>[>>>>>>>>]<<<<<<<<[+++++[-<++++++++>]<.<<<<<<<]

Uncompressed, with comments:

# parse input (max 255)
,[>++++++[-<-------->]<<[->++++++++++<]>>,]
>+>+>>+>+<<<<<<
[->>>
  # compute next fibonacci number
  [[-]<
    [->+<]>>
    [-<+<+>>]<
    # perform carries
    [->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<
      [->[-]>>>>>>+>+<<<<<<<<[->+<]]
    ]]]]]]]]]+>>>>>>>>
  ]<<<<<<<<
  # multiplication
  [->
    # extract next digit of F_n (most significant first)
    [-<+<<+>>>]<
    [->+<]>>>
    # move back to the end
    [<<<<<
      [->>>>>>>>+<<<<<<<<]>>>>>>>>>>>>>
    ]<<<<<<<<
    # digit wise multiplication (shifting current digit)
    [->>>
      [-<<<<<<<<+>>>>
        [->+>>+<<<]>
        [-<+>]>>>
      ]<<
      # shift previous total over one gap (in effect multiplying by 10)
      [->>>>>>>+>+<<<<<<<<]<+<<<<<<<<
    ]>>>[-]>>>>>
    # add product to total
    [[-]>
      [->+<]>
      # perform carries
      [-<+>
        [-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>
          [->>>>>>+>+<<<<<<<<[-]]
        ]]]]]]]]>
      ]<<[<]+>>>>>>>>
    ]<<<<<<<<
    [<<<<<<<<]>>>>>
    [>>>>>>>>]+<<<<<<<<
  ]>>>>>>>>>>>
  # overwrite previous product
  [<[-]>>
    [-<<+>>]>>>>>>>
  ]<<<<<<<<
  [<<<<<<<<]>>
]>>>>>>
# output product
[>>>>>>>>]<<<<<<<<
[+++++
  [-<++++++++>]<.<<<<<<<
]

Try it online!

Runtime for n = 100 is less than 1 second with the online interpreter (about 0.2s locally using my own interpreter). Maximum input is 255, but would require the interpreter to support ~54000 cells (the online interpreter seems to wrap on 64k).


Change Log

Saved around 130 bytes with better extraction of the current digit to multiply through by, and by merging add and carry into a single pass. It also seems to be a bit faster.

Saved another 250 bytes. I managed to reduce my multiplication scratch pad by two cells, which saves bytes just about everywhere by not having to shift so far between digits. I also dropped the carry after multiplying through by a digit, and instead perform a full carry whilst adding to the running total.

Chopped another 50, again with better extraction of the current digit to multiply through by, simply by not moving it forward the first iteration, and working from where it is. A few micro-optimization further down account for around ~10 bytes.

30 more gone. Marking digits that have already been taken with a 0 rather than a 1 makes them easier to locate. It also makes the check if the multiplication loop has finished somewhat simpler.

I reduced the scratch pad by another cell, for 80 more bytes. I did this by merging the marker for the previous product and the current running total, which reduces the shifts between gaps, and makes bookkeeping a bit easier.

Saved another 50, by eliminating yet another cell, reusing the marker for fibonacci digits to mark the last digit taken as well. I was also able to merge the loop to shift the previous totals with the digit-wise multiplication loop.

Saved 8 bytes on input parsing. Oops.

primo

Posted 2016-07-30T03:19:28.737

Reputation: 30 891

14

Python, 45 Bytes

a=b=o=1
exec"o*=a;a,b=b,a+b;"*input()
print o

Input is taken from stdin. Output for n = 100 finishes too quickly to accurately time. n = 1000 takes approximately 1s.

Sample Usage

$ echo 10 | python fib-orial.py
122522400

$ echo 100 | python fib-orial.py
3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000

primo

Posted 2016-07-30T03:19:28.737

Reputation: 30 891

13

Haskell 41 29 Bytes

1+11 bytes saved by @Laikoni's remarks.

f=1:scanl(+)1f
(scanl(*)1f!!)

1,f and !! are separate tokens. The first lines defines the fibonacci sequence, the second is a function that computes the sequence of fibonacci-orials and returns the n-th for a given n. It starts printing digits almost immediately even for n=1000.

Christian Sievers

Posted 2016-07-30T03:19:28.737

Reputation: 6 366

1You can get rid of the space (scanl(*)1f!!). – Laikoni – 2016-07-30T08:47:49.283

2

And there is a shorter fibonacci generator here: f=1:scanl(+)1f

– Laikoni – 2016-07-30T08:49:07.710

@Laikoni That's amazing, thanks! – Christian Sievers – 2016-07-30T09:15:16.210

first line makes sense only as part of a source file. second only in interpreter (and then, external parentheses are superfluous). – Will Ness – 2016-08-01T08:54:40.430

@WillNess That's why I wrote: First line defines, second is ... Doing so agrees with haskell entries from other users. Without the outer parentheses it would only be a code fragment (that could be followed by a value), with them it really is a function that can for example replace the dots in the expression map ... [1,50,100] – Christian Sievers – 2016-08-01T09:45:46.507

I'm not sure if that's allowed. Isn't it supposed to be full program? Again, not sure. – Will Ness – 2016-08-01T10:37:03.637

2

@WillNess I think I am not only justified by what other users do, but also by http://meta.codegolf.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet and http://meta.codegolf.stackexchange.com/questions/9031/unnamed-functions-in-code-golf?noredirect=1&lq=1 (but there is a lot more and I haven't read all)

– Christian Sievers – 2016-08-01T11:07:59.730

Can anyone explain why we actually need the parenthesis around around the expression in the second line? – flawr – 2016-08-05T22:48:52.710

1@flawr Would you accept 42+ as a function that adds 42? You shouldn't, because it is just an unfinished expression. But in Haskell we can add parentheses and get the section (42+), a way to write the function \n->42+n. Here it is the same, only with !! (the binary infix operator for indexing) instead of + and a more complicated first operand. – Christian Sievers – 2016-08-05T23:28:09.517

Ah now I see, thank you very much! – flawr – 2016-08-05T23:31:08.717

11

Python 2, 39 bytes

f=lambda n,a=1,b=1:n<1or a*f(n-1,b,a+b)

Test it on Ideone.

Dennis

Posted 2016-07-30T03:19:28.737

Reputation: 196 637

You may want to specify that it returns True in some cases. – Leaky Nun – 2016-07-30T17:19:34.027

5This would only return True for input 0, which isn't positive. – Dennis – 2016-07-30T17:22:54.867

6

J, 17 16 bytes

1 byte is golfed with even better solution by miles.

[:*/+/@(!|.)\@i.

The idea is the same as the original but instead of forming the matrix to operate on minor diagonals we form the diagonals on the fly.


Original

To get the first n fibonomials:

*/\(#{.+//.)!/~i.

Reading right to left...
Create the array of consecutive integers (i.) up to specified one, from that array create the table (/~) of binomial coefficients (!) calculated from every pair in the array, this table is Pascal's triangle top of whlocated at the end of the first row and all elements under the main diagonal are 0, thankfully to implementation of !. If you sum (+/) all minor diagonals (/.), you get Fibonacci numbers, but you need to take ({.) as much of first elements from the resulting array as the length (#) of the table itself. Then the product (*/) applied to consecutive prefixes (\) of the array results into desired sequence of fibonorials. If you wish you can take only the last one using 2 more bytes ({:) but I thought that displaying all of them is not a sin :).
NB. the previous code block is not a J function.

   {:*/\(#{.+//.)!/~i. 10
122522400

For big numbers in J you use x at the end:

   {:*/\(#{.+//.)!/~i. 100x
3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225...

The program runs on avarage 0.11s.

   100 timex '{:*/\(#{.+//.)!/~i.100x'
0.112124

Dan Oak

Posted 2016-07-30T03:19:28.737

Reputation: 263

1An alternative that is a function is [:*/+/@(!|.)\@i. using 16 bytes. It forms that same binomial coefficients along the table you generate using !/~ except that it forms that by taking prefixes of i.. – miles – 2016-07-30T23:06:02.020

4

Pyth, 13 bytes

u*Gs=[sZhZ)Q1

Demonstration

This employs a clever, non-typesafe trick. Five of the characters (u*G ... Q1) say that the output is the product of the input many numbers. The rest of the code generates the numbers.

=[sZhZ) updates the variable Z to the list [s(Z), h(Z)]. Then s sums that list, to be multiplied.

Z is initially 0. s, on ints, is the identity function. h, on its, is the + 1 function. So on the first iteration, Z becomes [0, 1]. s on lists is the sum function, as mentioned above. h is the head function. So the second iteration is [1, 0].

Here's a list:

Iter  Z          Sum
0     0          Not used
1     [0, 1]     1
2     [1, 0]     1
3     [1, 1]     2
4     [2, 1]     3
5     [3, 2]     5

These sums are multiplied up to give the result.

isaacg

Posted 2016-07-30T03:19:28.737

Reputation: 39 268

4

Mathematica 25 24 bytes

With thanks to Martin Ender.

1##&@@Fibonacci@Range@#&

1##&@@Fibonacci@Range@#&@100

Timing: 63 microseconds.

{0.000063, 
3371601853146468125386964065447576689828006172937411310662486977801540
6711385898686165008341900290675836651822917015531720110825745874313823
1009903039430687777564739516714333248356092511296002464445971530050748
1235056111434293619038347456390454209587101225261757371666449068625033
9995735521655245297254676280601708866020010771376138030271586483293355
0772869860576999281875676563330531852996518618404399969665040724619325
7877568825245646129366994079739720698147440310773871269639752334356493
6789134243905645353892122400388956268116279491329780860702550826683922
9003714114129148483959669418215206272639036409444764264391237153249138
8089634845995941928089653751672688740718152064107169357399466473375804
9722605947689699525073466941890502338235963164675705844341280523988912
2373033501909297493561702963891935828612435071136036127915741683742890
4150054292406756317837582840596331363581207781793070936765786629772999
8328572573496960944166162599743042087569978353607028409125185326833249
36435856348020736000000000000000000000000}

DavidC

Posted 2016-07-30T03:19:28.737

Reputation: 24 524

Alternately, with same byte count: 1##&@@Fibonacci~Array~#& – Greg Martin – 2017-01-05T19:18:29.057

4

Jelly, 8 bytes

RḶUc$S€P

My first submission in Jelly. It's not as short as @Dennis' answer, but its only 2 bytes longer with a different method.

Locally, it requires about 400ms compared to 380ms with @Dennis' version for n = 100.

Try it online!

Explanation

RḶUc$S€P  Input: n
R         Generate the range [1, 2, ..., n]
          For each value x in that range
 Ḷ          Create another range [0, 1, ..., x-1]
  U         Reverse that list
   c        Compute the binomial coefficients between each pair of values
    $       Bind the last two links (Uc) as a monad
     S€   Sum each list of binomial coefficients
          This will give the first n Fibonacci numbers
       P  Take the product of those to compute the nth Fibonacci-orial

miles

Posted 2016-07-30T03:19:28.737

Reputation: 15 654

3

PARI/GP, 29 bytes

f=n->prod(i=1,n,fibonacci(i))

Or alternatively:

f=n->prod(i=a=!b=0,n,b=a+a=b)

primo

Posted 2016-07-30T03:19:28.737

Reputation: 30 891

3

R, 99 96 78 76 66 bytes

This answer is uses Binet's Formula, as well as the prod(x)function. Since R doesn't have a build-in Phi value, I defined it myself :

p=(1+sqrt(5))/2;x=1;for(n in 1:scan())x=x*(p^n-(-1/p)^n)/sqrt(5);x

It works under 5 seconds, but R tends to give Inf as an answer for those big numbers...

Ungolfed :

r=sqrt(5)
p=(1+r)/2 
x=1
for(n in 1:scan())        
    x=x*(p^n-(-1/p)^n)/r    
x

-2 bytes thanks to @Cyoce !
Oh, do I love this site ! -10 bytes thanks to @user5957401

Frédéric

Posted 2016-07-30T03:19:28.737

Reputation: 2 059

Might be able to save a bit by storing sqrt(5) to a variable – Cyoce – 2016-08-07T06:20:41.083

since you only use N once, you can just call scan inside the 1:N bit. i.e. for(n in 1:scan()).

You can also save a few characters by just using * instead of the prod() function in your for loop.

Your for loop is only one line, so you don't need the curly braces either. – user5957401 – 2016-08-10T19:31:14.183

Nice idea to use Binet's formula. In your spirit but only 53 bytes is function(n,N=1:n,p=5^.5)prod(((1+p)^N-(1-p)^N)/2^N/p) – Michael M – 2018-02-19T09:19:20.333

3

R, 82, 53, 49 bytes (48 bytes w/ different input style)

b=d=1;a=0;for(i in 1:scan()){d=d*b;b=a+b;a=b-a};d

If we can just precede the code with the input number, we get the 48 byte

->n;b=d=1;a=0;for(i in 1:n){d=d*b;b=a+b;a=b-a};d

EDIT: New code. Original is below:

a=function(n)ifelse(n<3,1,{v=c(1,1,3:n);for(i in 3:n)v[i]=v[i-1]+v[i-2];prod(v)})

Won't return anything other than Inf for a(100) though. And it won't work for anything but non-negative integers.

Ungolfed:

a=function(n){
   if(n<3) return(1)
   v=c(1,1,3:n)
   for(i in 3:n)
       v[i]=v[i-1]+v[i-2]
   prod(v)
}

user5957401

Posted 2016-07-30T03:19:28.737

Reputation: 699

3

Brachylog, 31 bytes

,[1:0]:?:{hH,?bh:H+g:?c.}irbb*.

Try it online!

Leaky Nun

Posted 2016-07-30T03:19:28.737

Reputation: 45 011

2

Brain-Flak, 54 bytes

([{}]<(())>){(({})()<{({}()<([({})]({}{}))>)}{}{}>)}{}

Try it online!

Multiplication in Brain-Flak takes a long time for large inputs. Just multiplying F100 by F99 with a generic multiplication algorithm would take billions of years.

Fortunately, there's a faster way. A generalized Fibonacci sequence starting with (k, 0) will generate the same terms as the usual sequence, multiplied by k. Using this observation, Brain-Flak can multiply by a Fibonacci number just as easily as it can generate Fibonacci numbers.

If the stack consists of -n followed by two numbers, {({}()<([({})]({}{}))>)}{}{} will computen iterations of the generalized Fibonacci sequence and discard all by the last. The rest of the program just sets up the initial 1 and loops through this for all numbers in the range n...1.

Here's the same algorithm in the other languages provided by this interpreter:

Brain-Flak Classic, 52 bytes

({}<(())>){(({})[]<{({}[]<(({}<>)<>{}<>)>)}{}{}>)}{}

Try it online!

Brain-Flueue, 58 bytes

<>(<(())>)<>{(({}<>)<{({}({}))({}[()])}{}>[()]<>)}<>({}){}

Try it online!

Mini-Flak, 62 bytes

([{}()](())){(({})()({({}()([({})]({}{}))[({})])}{}{})[{}])}{}

Try it online!

Nitrodon

Posted 2016-07-30T03:19:28.737

Reputation: 9 181

2

Javascript (ES6), 51 39 bytes

Recursive implementation (39 bytes)

f=(n,a=p=i=b=1)=>++i<n?f(n,b,p*=b+=a):p

Original implementation (51 bytes)

n=>{for(i=a=b=p=1;++i<n;){c=a;a=b;p*=b+=c}return p}

Note: Starts rounding errors for the Fibonacci-orial of 16, 100 is just Infinity, runs in what appears to be <1 second.

Pandacoder

Posted 2016-07-30T03:19:28.737

Reputation: 190

I made an alternate 53-byte version n=>[...Array(n)].reduce(p=>(c=a,a=b,p*=b+=c),a=1,b=0) only to discover that you'd counted the f= which isn't required saving you 2 bytes. – Neil – 2016-07-30T09:00:28.937

Fair point. My rationale was so it was callable and reusable rather than just callable. – Pandacoder – 2016-07-30T13:38:54.187

Sure, but if someone does want to reuse it then they still have the option of naming it. – Neil – 2016-07-30T20:08:56.480

@Neil Well now I went and re-implemented it and now the f= is mandatory or else it can't actually execute. :D – Pandacoder – 2016-08-15T22:18:32.273

Well at least you fixed the byte count for the original implementation. – Neil – 2016-08-15T22:53:55.840

f=(n,a=p=b=1)=>n>2?f(n-1,b,p*=b+=a):p for 37 bytes ;) – Shieru Asakoto – 2018-02-20T03:01:39.300

2

Ruby, 39 bytes

->n{f=i=b=1;n.times{f,i,b=i,f+i,b*f};b}

Lynn

Posted 2016-07-30T03:19:28.737

Reputation: 55 648

36: ->n{f=i=b=1;n.times{b*=f;i=f+f=i};b} – G B – 2018-02-23T09:19:15.110

2

DC (GNU or OpenBSD flavour), 36 bytes

File A003266-v2.dc:

0sA1sB1?[1-d0<LrlBdlA+sBdsA*r]dsLxrp

(no trailing newline)

...now the result is held on the stack instead of using a named register (is Y in version 1). The r command is not available in the original dc (see RosettaCode's Dc page).

Run:

$ time dc -f A003266-v2.dc <<< 100
337160185314646812538696406544757668982800617293741131066248697780154\
067113858986861650083419002906758366518229170155317201108257458743138\
231009903039430687777564739516714333248356092511296002464445971530050\
748123505611143429361903834745639045420958710122526175737166644906862\
503399957355216552452972546762806017088660200107713761380302715864832\
933550772869860576999281875676563330531852996518618404399969665040724\
619325787756882524564612936699407973972069814744031077387126963975233\
435649367891342439056453538921224003889562681162794913297808607025508\
266839229003714114129148483959669418215206272639036409444764264391237\
153249138808963484599594192808965375167268874071815206410716935739946\
647337580497226059476896995250734669418905023382359631646757058443412\
805239889122373033501909297493561702963891935828612435071136036127915\
741683742890415005429240675631783758284059633136358120778179307093676\
578662977299983285725734969609441661625997430420875699783536070284091\
2518532683324936435856348020736000000000000000000000000

real    0m0.005s
user    0m0.004s
sys     0m0.000s

Trying to explain:

tos is the contents of the top of the stack without removing it.
nos is the element below tos.

0 sA # push(0) ; A=pop()
1 sB # push(1) ; B=pop()
1    # push(1)
     # this stack position will incrementally hold the product
?    # push( get user input and evaluate it )
[    # start string
 1-  # push(pop()-1)
 d   # push(tos)
 0   # push(0)
 <L  # if pop() < pop() then evaluate contents of register L
 r   # exchange tos and nos
     # now nos is the loop counter
     # and tos is the bucket for the product of the fibonacci numbers
 lB  # push(B)
 d   # push(tos)
 lA  # push(A)
 +   # push(pop()+pop())
     # now tos is A+B, nos still is B 
 sB  # B=pop()
     # completes B=A+B
 d   # push(tos)
 sA  # A=pop()
     # completes B=A
     # tos (duplicated new A from above) is the next fibonacci number
 *   # push(nos*tos)
     # tos now is the product of all fibonacci numbers calculated so far
 r   # exchange tos and nos
     # now tos is the loop counter, nos is the product bucket
]    # end string and push it
d    # push(tos)
sL   # L=pop()
x    # evaluate(pop())
r    # exchange tos and nos
     # nos now is the former loop counter
     # tos now is the complete product. \o/
p    # print(tos)
     # this does not pop() but who cares? :-P

DC, 41 bytes

...straight forward, no tricks:

File A003266-v1.dc:

0sA1sB1sY?[1-d0<LlBdlA+sBdsAlY*sY]dsLxlYp

(no trailing newline)

Run:

$ for i in $(seq 4) ; do dc -f A003266-v1.dc <<< $i ; done
1
1
2
6
$ time dc -f A003266-v1.dc <<< 100
337160185314646812538696406544757668982800617293741131066248697780154\
067113858986861650083419002906758366518229170155317201108257458743138\
231009903039430687777564739516714333248356092511296002464445971530050\
748123505611143429361903834745639045420958710122526175737166644906862\
503399957355216552452972546762806017088660200107713761380302715864832\
933550772869860576999281875676563330531852996518618404399969665040724\
619325787756882524564612936699407973972069814744031077387126963975233\
435649367891342439056453538921224003889562681162794913297808607025508\
266839229003714114129148483959669418215206272639036409444764264391237\
153249138808963484599594192808965375167268874071815206410716935739946\
647337580497226059476896995250734669418905023382359631646757058443412\
805239889122373033501909297493561702963891935828612435071136036127915\
741683742890415005429240675631783758284059633136358120778179307093676\
578662977299983285725734969609441661625997430420875699783536070284091\
2518532683324936435856348020736000000000000000000000000

real    0m0.006s
user    0m0.004s
sys     0m0.004s

user19214

Posted 2016-07-30T03:19:28.737

Reputation:

Explanation please? – Leaky Nun – 2016-07-30T12:13:00.023

Any link to online interpreter or official website? – Leaky Nun – 2016-07-30T12:15:37.633

1*sigh!* ... writing dc code definitely is easier than explaining it... – None – 2016-08-01T12:05:36.703

1Yeah, we really need an IDE with some kind of crazy multiple-stack visualisation gadget... that would be sweet. – Joe – 2016-08-01T15:13:34.133

1I have several ideas what to add as new commands, but the idea with the highest impact seems to be: Add a "change default stack" command. ;-) – None – 2016-08-01T17:23:09.313

2...or swap default stack with a named register. That would make more knots in users' brains but would not need the default stack to have a name... ]:-) – None – 2016-08-01T17:29:34.767

1Yes, that would definitely be handy! I'd also like to clear a single item, rotate items that aren't at the top of the stack, and maybe shift the top n items to another stack at once. For now, though, I still don't know how to compile dc from source. :/ – Joe – 2016-08-06T05:21:22.907

I only can give unixish answers: Gab a not so bloated version of Dc. Put an empty sigset.h in the same directory as the sources and compile by gcc -I. -DSHELL='"/bin/sh"' dc.c -s -o dc. (Tested on Debian-8.5)

– None – 2016-08-06T08:08:36.870

2

Java, 165 bytes

Golfed:

BigInteger f(int n){BigInteger[]a={BigInteger.ZERO,BigInteger.ONE,BigInteger.ONE};for(int i=0;i<n;){a[++i%2]=a[0].add(a[1]);a[2]=a[2].multiply(a[i%2]);}return a[2];}

This is yet another case where BigInteger being required due to large numbers. However, I was able to keep the text BigInteger to a minimum, keeping the size down. I also compared with static imports, and it made the total length longer.

This program works by tracking three numbers in an array. The first two are the previous two Fibonacci numbers. The third is the accumulated value. The loop starts out by calculating the next value and storing it in alternating (0, 1, 0, 1, ...) array indices. This avoids needing to shift values with costly (in terms of source size) assignment operations. Then grab that new value and multiply it into the accumulator.

By avoiding temporary objects and limiting the loop to two assignment operators, I was able to squeeze out quite a few bytes.

Ungolfed:

import java.math.BigInteger;

public class Fibonacci_orial {

  public static void main(String[] args) {
    // @formatter:off
    String[][] testData = new String[][] {
      { "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" }
    };
    // @formatter:on

    for (String[] data : testData) {
      System.out.println("Input: " + data[0]);
      System.out.println("Expected: " + data[1]);
      System.out.print("Actual:   ");
      System.out.println(new Fibonacci_orial().f(Integer.parseInt(data[0])));
      System.out.println();
    }
  }

  // Begin golf
  BigInteger f(int n) {
    BigInteger[] a = { BigInteger.ZERO, BigInteger.ONE, BigInteger.ONE };
    for (int i = 0; i < n;) {
      a[++i % 2] = a[0].add(a[1]);
      a[2] = a[2].multiply(a[i % 2]);
    }
    return a[2];
  }
  // End golf

}

Program output:

Input: 1
Expected: 1
Actual:   1

Input: 2
Expected: 1
Actual:   1

Input: 3
Expected: 2
Actual:   2

Input: 4
Expected: 6
Actual:   6

Input: 5
Expected: 30
Actual:   30

Input: 6
Expected: 240
Actual:   240

Input: 7
Expected: 3120
Actual:   3120

Input: 8
Expected: 65520
Actual:   65520

Input: 9
Expected: 2227680
Actual:   2227680

Input: 10
Expected: 122522400
Actual:   122522400

Input: 11
Expected: 10904493600
Actual:   10904493600

Input: 12
Expected: 1570247078400
Actual:   1570247078400

Input: 13
Expected: 365867569267200
Actual:   365867569267200

Input: 14
Expected: 137932073613734400
Actual:   137932073613734400

Input: 15
Expected: 84138564904377984000
Actual:   84138564904377984000

Input: 16
Expected: 83044763560621070208000
Actual:   83044763560621070208000

Input: 17
Expected: 132622487406311849122176000
Actual:   132622487406311849122176000

Input: 18
Expected: 342696507457909818131702784000
Actual:   342696507457909818131702784000

Input: 19
Expected: 1432814097681520949608649339904000
Actual:   1432814097681520949608649339904000

Input: 20
Expected: 9692987370815489224102512784450560000
Actual:   9692987370815489224102512784450560000

Input: 100
Expected: 3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000
Actual:   3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000

user18932

Posted 2016-07-30T03:19:28.737

Reputation:

2

C# 110 109 107 103 101 94 Bytes

using i=System.Numerics.BigInteger;i f(i n){i a=0,b=1,x=1;for(;n-->0;)x*=a=(b+=a)-a;return x;}

Explanation

//Aliasing BigInteger saves a few bytes
using i=System.Numerics.BigInteger;

//Since BigInteger has an implicit from int we can also change the input
//and save two more bytes.
i f(i n)
{
    //using an alternative iterative algorithm (link to source below) to cut out the temp variable
    //b is next iteration, a is current iteration, and x is the running product
    i a = 0, b = 1, x = 1; 

    //post decrement n down to zero instead of creating a loop variable
    for (; n-- > 0;)

        //The bracket portion sets the next iteration             
        //get the current iteration and update our running product
        x *= a = (b += a) - a;

    return x;
}

Iterative Fib algorithm

user19547

Posted 2016-07-30T03:19:28.737

Reputation:

Given this performed so much better than I had expected I wanted to find the max N that would return in under 5 seconds, I came out with 1540 which gives a number that is 247441 digits long. – None – 2016-08-11T23:36:36.207

Impressive. How long does 1541 take to calculate, out of curiosity? – Pandacoder – 2016-08-15T22:25:19.610

@Pandacoder So with the recent change to the algorithm it has gotten significantly faster. 1541 in 755 ms so i'm going to find the new sub 5 max now. – None – 2016-08-15T22:29:25.453

@Pandacoder so the run time is varying by a fair bit ~100ms but 2565 seems to average about 5 seconds – None – 2016-08-15T22:44:29.640

How long is the number for that? – Pandacoder – 2016-08-15T22:45:47.387

@Pandacoder Came out to 686861 digits. – None – 2016-08-15T22:46:52.627

1

05AB1E, 6 4 bytes

LÅfP

Try it online!

-1 from Robbie0630, -1 more from an improvement on his suggestion.

Magic Octopus Urn

Posted 2016-07-30T03:19:28.737

Reputation: 19 422

1@robbie0630 LÅfP for 4, haven't looked here in a long time ;), you have to actually be careful with it doesn't work on 2-byte commands. Also, with L, many things vectorize automatically (even list commands) so you don't need an iterator :). – Magic Octopus Urn – 2018-02-20T17:14:57.687

1

cQuents, 16 15 bytes

=1:Zb$
=1,1:Z+Y

Try it online!

Explanation

=1:       Sequence with first term = 1
   Zb$    Each term equals the previous times the next line at the current index

=1,1:     Sequence with the first two terms = 1
     Z+Y  Each term equals the previous two terms added together

Stephen

Posted 2016-07-30T03:19:28.737

Reputation: 12 293

1

Pyt, 5 bytes

←ř⁻ḞΠ

Input is from stdin. Approximately instantaneous for n=100. Takes less than a second for n=1000.

Explanation:

←            Get input
 ř           Get [1,2,...,input]
  ⁻          Decrement all elements by 1
   Ḟ         Get Fibonacci numbers
    Π        Product

Try it online!

mudkip201

Posted 2016-07-30T03:19:28.737

Reputation: 833

1

Fortran 95, 118 bytes

This version explicitly declares P as an integer, thus the limit is given by the size of the integer (4 bytes by default).

program o
integer,parameter::n=20
integer F(n),P
P=1
F(:2)=1
do i=3,n
F(i)=F(i-1)+F(i-2)
P=P*F(i)
enddo
print*,P
end

If I extend the size of the integer to 16 bytes, the byte count of the code increases by 3: integer*16 F(n),P.

One can also omit P from the declaration and use it as a 4 byte floating point, then the byte count is reduced by 2.

Thiago Oleinik

Posted 2016-07-30T03:19:28.737

Reputation: 341

1

dc, 38 40 30 28 bytes

?si1d[sadlarla+zli>b]sbzli>b[*z1<*]ds*xf

si1d[sadlarla+zli>b*]sbzli>b

Expanded:

si     # Take input from top of stack and store it in register `i'
1d     # Push 1 on stack and duplicate
[      # Open macro definition
 sa    #  Store most recent term of Fibonacci sequence in register `a'
 d     #  Duplicate second most recent term
 la    #  Push most recent term onto stack
 r     #  Rotate top two items on stack
 la    #  Push most recent term onto stack (again)
       #  At this point, we've essentially duplicated the top two terms of the stack
       #    without altering the order of the terms
 +     #  Add top two terms of stack (generate next Fibonacci number)
 zli>b #  Take stack depth and load input (target number of terms); if we don't have
       #  enough terms yet, execute `b'
 *     #  Once we've generated all the terms (factors, really), we'll multiply
       #    them, one * for every time we iterated to generate a term
]sb    # Store macro in register `b'
zli>b  # Look familiar? This way, we change the "do-while" (`dsbx') to just "while"
       # Leave result on top of stack

Joe

Posted 2016-07-30T03:19:28.737

Reputation: 895

z as implicit loop counter in zli!= is nice!!! And I like your idea to collect all factors on the stack and multiply them in a loop... ;-) ...but it hangs on input 1 and 2 here on GNU dc... :-( – None – 2016-07-30T19:31:32.693

@yeti Thanks :D And thanks for pointing out the bug; I hadn't noticed. – Joe – 2016-07-31T00:02:35.620

1

Brain-Flak, 110 104 100 bytes

Try it online!

({}<((())<>)>){({}[()]<<>(({})<>({}<>)<>)>)}<>{}([[]]()){({}()<({}<>)<>({<({}[()])><>({})<>}{})>)}{}

Explanation

First we run an improved version of the Fibonacci sequence generator curtesy of Dr Green Eggs and Iron Man

({}<((())<>)>){({}[()]<<>(({})<>({}<>)<>)>)}<>{}

Then while the stack has more than one item on it

([[]]()){({}()<...>)}

multiply the top two items

({}<>)<>({<({}[()])><>({})<>}{})

and pop the extra zero

{}

Post Rock Garf Hunter

Posted 2016-07-30T03:19:28.737

Reputation: 55 382

1Unfortunately, I think this is invalid since it takes over 10 seconds for an input of 25. The algorithm is very inefficient (just like the language is), so calculating it for 100 would probably take hours. – James – 2016-07-30T13:14:08.977

1

Mathematica - 32 26 bytes

Fibonacci@i~Product~{i,#}&

@MartinEnder chopped 6 bytes!

Yytsi

Posted 2016-07-30T03:19:28.737

Reputation: 3 582

1

GAP 28 Bytes

Didn't know before today that GAP has a Fibonacci builtin.

n->Product([1..n],Fibonacci)

Christian Sievers

Posted 2016-07-30T03:19:28.737

Reputation: 6 366

Can you link to GAP? No idea what it is. – Leaky Nun – 2016-07-30T08:38:12.310

Oh sure (but I'm not the first one to use it here...) – Christian Sievers – 2016-07-30T08:44:05.893

1

Ruby, 85 Bytes

g =->x{(1..x).to_a.collect{|y|(0..y).inject([1,0]){|(a,b),_|[b, a+b]}[0]}.inject(:*)}

Turned out fine, but there's probably a shorter solution.

Fast Fibonnaci calculation taken from here: link

Test it here

Seims

Posted 2016-07-30T03:19:28.737

Reputation: 631

1

Julia, 36 bytes

!x=[([1 1;1 0]^n)[2]for n=1:x]|>prod

Lynn

Posted 2016-07-30T03:19:28.737

Reputation: 55 648

1

JavaScript (ES6), 46 bytes

f=(n,a=1,b=1,c=i=1)=>n==i?c:f(n,b,a+b,c*b,++i)

Uses recursion and accumulator variables. Rounding errors start at f(16).

c.P.u1

Posted 2016-07-30T03:19:28.737

Reputation: 1 049

1

Ruby, 35 bytes

A Ruby fork of Dennis's Python answer. Golfing suggestions welcome.

f=->n,a=1,b=1{n<1?1:a*f[n-1,b,a+b]}

Try it online!

Ungolfed:

def f(n)
  a=b=z=1
  (1..n).each do |i|
     z*=a
     a,b=b,a+b
  end
  return z
end

Sherlock9

Posted 2016-07-30T03:19:28.737

Reputation: 11 664

n<1?1:a*f... is n<1||a*f...? – Stan Strum – 2018-02-22T05:35:08.130

@StanStrum In Ruby, true can't be coerced into Integer. – Sherlock9 – 2018-02-23T08:08:47.733

1

Clojure, 70 bytes

Clojure isn't really a good language for code golf. Oh well.

Try it at http://tryclj.com.

(last(nth(iterate(fn[[a b r]][b(+ a b)(* r(+ a b))])[0N 1 1])(dec n)))

user16973

Posted 2016-07-30T03:19:28.737

Reputation: 11

1

Forth, 55 bytes

Uses an iterative approach, built upon my Fibonacci answer in Forth. The results overflow arithmetically for n > 10. The answer is case-insensitive.

: f >r 1 1 r@ 0 DO 2dup + LOOP 2drop 1 r> 0 DO * LOOP ;

Try it online

mbomb007

Posted 2016-07-30T03:19:28.737

Reputation: 21 944

1

Swift, 68 Bytes

func f(n:Int,_ a:Int=1,_ b:Int=1)->Int{return n<1 ?1:a*f(n-1,b,a+b)}

Alexander - Reinstate Monica

Posted 2016-07-30T03:19:28.737

Reputation: 481

1

ForceLang, 140 bytes

def s set
s a 0
s b s p 1
s k io.readnum()
if k=1
goto b
label a
s c a+b
s a b
s b c
s p p.mult c
s k k+-1
if k+-1
goto a
label b
io.write p

SuperJedi224

Posted 2016-07-30T03:19:28.737

Reputation: 11 342

1

Racket 130 bytes

(define(fb n)(cond[(or(= n 1)(= n 2))1][(+(fb(- n 1))(fb(- n 2)))]))
(define(fo n)(for/product((i(range 1(+ 1 n))))(fb i)))(fo n))

Ungolfed:

(define (f n)
  (define (fibonacci n)
    (cond
      [(or (= n 1)(= n 2)) 1]
      [else (+ (fibonacci (- n 1)) (fibonacci(- n 2)))] ))
  (define (f_orial n)
    (for/product ((i (range 1 (add1 n))))
      (fibonacci i)))
  (f_orial n))

Testing:

(f 1)
(f 2)
(f 3)
(f 4)
(f 5)
(f 6)
(f 7)
(f 8)
(f 9)
(f 10)
(f 11)
(f 12)
(f 20)
(f 30)

Output:

1
1
2
6
30
240
3120
65520
2227680
122522400
10904493600
1570247078400
9692987370815489224102512784450560000
607373569868916007005878071331449502263924414704952629297115029592606043656028160000000

rnso

Posted 2016-07-30T03:19:28.737

Reputation: 1 635

0

Pushy, 12 bytes

1&{2-:2d+;P#

Try it online!

This is a straightforward implementation of the specification:

1&    \ Push 1, twice.
{     \ Shift stack left (so input is on top).
      \ Stack: [1, 1, n]

2-:   \ Input - 2 times do (this consume input):
2d+;  \   Push the sum of the last 2 values.
      \ Stack: [fib(1), fib(2)... fib(n)]

P#    \ Output the stack product.

FlipTack

Posted 2016-07-30T03:19:28.737

Reputation: 13 242

0

R, 36 34 bytes

prod(numbers::fibonacci(scan(),T))

Takes input from stdin. -2 bytes due to @Jardo Dubbeldam.

rturnbull

Posted 2016-07-30T03:19:28.737

Reputation: 3 689

1prod(numbers::fibonacci(scan(),T)) is a shorter builtin implementation :) – JAD – 2017-01-05T16:15:29.303

@JarkoDubbeldam Haha, thanks! You would think I would have tried that, given I was just talking to you about that function... – rturnbull – 2017-01-05T16:48:53.080

0

Perl 6, 23 bytes

{[*] (1,&[+]...*)[^$_]}

Try it online!

  • 1, &[+] ... * is the infinite Fibonacci sequence.
  • [^$_] takes the first $_ elements of the sequence, where $_ is the argument to the function.
  • [*] reduces that subsequence with multiplication.

Sean

Posted 2016-07-30T03:19:28.737

Reputation: 4 136

0

Javascript,44 bytes

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

based on this Fibbonaci sequence

SuperStormer

Posted 2016-07-30T03:19:28.737

Reputation: 927

0

Husk, 4 bytes

Π↑İf

Try it online!

Explanation

Π↑İf  -- input is an integer N, for example 5
  İf  -- fibonacci numbers: [1,1,2,3,5,8,13,21,34…]
 ↑    -- take N: [1,1,2,3,5]
Π     -- product: 30

ბიმო

Posted 2016-07-30T03:19:28.737

Reputation: 15 345

0

J, 30 Bytes

*/@:([{.(,{:+{:@}:)@]^:[&1 1x)

Probably improvable.

Explanation:

*/@:(                        )    | Product of
     [{.                          | First n
        (,{:+{:@}:)@]^:[&1 1x     | n+2 fibonacci numbers:
                        &1 1x     | Apply with the list 1 1 (x specifies extended prescision)
                     ^:[          | n times:
        (,{:+{:@}:)@]             | Append the sum of the last two numbers

Computes the Fibonacc-orial of 100 in 2 ms.

Bolce Bussiere

Posted 2016-07-30T03:19:28.737

Reputation: 970

0

Scala, 84 bytes

def f(i:Int,v:BigInt=1,p:BigInt=0,c:BigInt=1):BigInt=if(i==0)c else f(i-1,v+p,v,c*v)

Tail recursive function, based on this Fibonnaci implementation. This version adds a parameter to keep track of the running product.

Run it online (with test cases)

oowekyala

Posted 2016-07-30T03:19:28.737

Reputation: 211

0

Pyt, 3 bytes

Zero indexed

Thanks to mudkip201 for catching my mistake

řḞΠ

Try it online!

         implicit input
ř        range from input to one
 Ḟ       fibonacci over array
  Π      product
         implicit output

FantaC

Posted 2016-07-30T03:19:28.737

Reputation: 1 425

I think you meant Π, not Ʃ – mudkip201 – 2018-02-18T19:22:23.447

@mudkip201 good catch – FantaC – 2018-02-19T03:14:20.947

0

Jelly, 4 bytes

RÆḞP

Try it online!

Explanation

R       inclusive range
 ÆḞ     nth fibonacci number
   P    product

chromaticiT

Posted 2016-07-30T03:19:28.737

Reputation: 211

0

Japt, 7 bytes

õ@MgXÃ×

Try it


Explanation

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

Shaggy

Posted 2016-07-30T03:19:28.737

Reputation: 24 623

0

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)))

Renzo

Posted 2016-07-30T03:19:28.737

Reputation: 2 260

0

Pyke, 6 5 bytes

Sm.bB

Try it here!

product(map(nth_fib, input))

Blue

Posted 2016-07-30T03:19:28.737

Reputation: 26 661

0

ngn/apl, 20 bytes

{×/(+/(!∘⌽⍨⍳))¨1+⍳⍵}

Try it here.

Explanation

{×/(+/(!∘⌽⍨⍳))¨1+⍳⍵}  Input: n
                  ⍵   Get n
                 ⍳    Form the range [0, 1, ..., n-1]
               1+     Add 1 to each to get [1, 2, ..., n]
              ¨       For each value x
           ⍳            Form the range [0, 1, ..., x-1]
         ⌽⍨             Reverse it to get [x-1, ..., 1, 0]
       !∘               Find the binomial coefficient between each pair in the original
                        range and reversed range
    +/                  Reduce using addition to get the xth Fibonacci number
 ×/                   Reduce using multiplication and return

miles

Posted 2016-07-30T03:19:28.737

Reputation: 15 654

0

Maple, 40 bytes

`*`~(seq(combinat:-fibonacci(i),i=1..n))

Usage

> f:=n->`*`~(seq(combinat:-fibonacci(i),i=1..n));
> f(10);
  122522400

This uses the built-in combinat:-fibonacci as well as the element-wise operator ~ to multiply the terms in the sequence.

DSkoog

Posted 2016-07-30T03:19:28.737

Reputation: 560

0

PowerShell v3+, 86 bytes

param($n)$f=,1*$n;2..$n|%{$f[$_]=$f[$_-1]+$f[$_-2]};"[bigint]"+($f[0..$n]-join'*')|iex

The [bigint] data structure was introduced in .NET Framework 4, hence the PowerShell v3+ requirement.

Takes input $n, constructs a new array $f pre-populated with 1s, of length $n. Then we loop from 2..$n and each iteration simply construct the next Fibonacci value. Finally, we take $f from 0 up to $n and -join it together with * (so we have a big ol' string like 1*1*2*3*5*8*...), prepend that string with the cast "[bigint]", and pipe that to |iex (short for Invoke-Expression and similar to eval). The result is left on the pipeline, and output is implicit. We get by with only one data cast, as PowerShell uses the explicit cast from the left-hand-side of an operator as an implicit cast on the right-hand-side.

Tosses an array-index-out-of-bounds style exception to STDERR, but that's shorter than setting the loop to 2..($n-1) ;-)


If we didn't need to go higher than ~55, we can get rid of the cast and parens for the following at 73 bytes. Input values above 13 will result in scientific notation output.

param($n)$f=,1*$n;2..$n|%{$f[$_]=$f[$_-1]+$f[$_-2]};$f[0..$n]-join'*'|iex

AdmBorkBork

Posted 2016-07-30T03:19:28.737

Reputation: 41 581

0

05AB1E, 12 bytes

X$ÍF‚D`ŠŠO}P

Explanation

X$           # push 1, 1, input
  ÍF      }  # input-2 times do:
    ‚D       # pair top 2 elments and duplicate
      `ŠŠ    # flatten one pair and move the remaining pair to the top of the stack
         O   # sum the pair
           P # product of stack
             # implicitly print

Try it online

Emigna

Posted 2016-07-30T03:19:28.737

Reputation: 50 798

ÅF - Fibonacci numbers. – Magic Octopus Urn – 2017-01-05T15:57:59.187

0

Fourier, 34 bytes

Basically, just a small tweak of the Fibonacci sequence program on Fourier's esolangs page.

1~F~x~yI~k(x*F~Fy+x~gy~xg~yi^~i)Fo

If you want to try this program online, I would suggest using Dennis' site, http://fourier.tryitonline.net, because on http://labs.turbo.run/beta/fourier an input of 100 leads to an output of infinity.

Try it online!

Beta Decay

Posted 2016-07-30T03:19:28.737

Reputation: 21 478

0

Lithp, 362 bytes

(
    (platform v1)
    (import "lists")
    (var FL (dict))
    (def fib #N::((if (< N 2) (1) ((+ (fibFL (- N 1)) (fibFL (- N 2)))))))
    (def fibFL #N::((if (dict-present FL N) ((dict-get FL N)) ((var I (fib N)) (set FL (dict-set FL N I)) (I)))))
    (def fib-orial #N::((prod (map (seq 1 N) (scope #I::((fib I)))))))
    (each (seq 2 15) (scope #N :: ((print (fib-orial N)))))
)

As with the JavaScript answer, rounding errors occur at orial of 16. Therefore this program prints the orial of 2 to 15.

This one was tricky, because the run time was well over 10 seconds for even a small number. I solved this by using a dictionary to store results of calls to fib. The result is that instead of 10 seconds and over 100,000 function calls, the code often runs in under 200ms and results in only ~6700 function calls.

Andrakis

Posted 2016-07-30T03:19:28.737

Reputation: 361