title: Draw the NASA worm logo

text:
# Question
Title: Draw the NASA worm logo
**Introduction**

On 30 May 2020, NASA and SpaceX launched a crewed rocket to the international space station on the SpaceX Demo 2 mission. This is the first time humans have been launched into orbit from American soil since the retiring of the Space Shuttle in 2011, and the first time ever that a private company has launched astronauts into orbit. The rocket bore the iconic NASA worm logo, the first time this logo has been used since 1992. Let's celebrate NASA and SpaceX's achievement by drawing the worm logo.

I looked on the internet for a specification of this logo. The best I could find was on Reddit. However there are a number of issues with this version. For example the thickness of vertical and curved lines is defined as 1 but for horizontal lines it is 0.95 and there is no specification of how to transition between the two thicknesses.

**Challenge**

Draw the simplified version of the NASA worm logo defined in the SVG below.

Some notes on the design:

* All parts of the worm are 100 units wide.
* All diagonal lines have a slope of 24/7. This takes advantage of the pythagorean triple `24^2 + 7^2 = 25^2` to ensure accurate and consistent positions of the thickness of the worm and the beginnings and endings of arcs while using only integer coordinates.
* As the vertical height of the arms of the A's are not multiples of 24, the `x` coordinates of the bottoms of the A are not integers, but they are integer multiples of `1/6`.
* The S is 500 units high, from `y=100` to `y=600`. The curved parts of the S have internal and external radii of 50 and 150.
* The internal and internal radii of the curved parts of the N and A's are 25 and 125. The `y` coordinates of the centres of these arcs are `y=215` and `y=485`. This means that the tops and bottoms of the arcs extend above and below the top and bottom of the S, specifically to `y=90` and `y=610`. This is similar to the official logo.
* The ends of the N terminate at `y=100 and y=600.` Similarly, the ends of the A's terminate at `y=600`.
* There is an overlap region between the first A and the S. The length of the upper and lower arms of the S is chosen to be 231.67 units so that this overlap region is triangular. The top of the lower arm of the S meets the A at `1043.33,600`
* In addition to the SVG script, A PNG image (not perfectly to scale) is given with annotations of the coordinates of all parts of the logo: all four coordinates of each straight section and the centre and radius of each curved section. Note that because of the way SVG defines arcs, the coordinates of the centres of the curved sections do not appear in the SVG script. Curved sections are shown in black and straight sections are shown in red, with the exception of the lower arm of the S, which is shown in blue to distinguish it from the part of the A which it overlaps.

**PNG**

**SVG**

```
<svg xmlns="http://www.w3.org/2000/svg" viewbox=0,0,2000,700>

<path fill="red" d="M110,600 L110,215 A125,125,0,0,1,355,180 L446,492 A25,25,0,0,0,495,485 L495,100 L595,100 L595,485 A125,125,0,0,1,350,520 L259,208 A25,25,0,0,0,210,215 L210,600"/>

<path fill="red" d="M587.5,600 L710,180 A125,125,0,0,1,950,180 L1072.5,600 L968.33,600 L854,208 A25,25,0,0,0,806,208 L691.67,600" />

<path fill="red" d="M1043.33,500 L1275,500 A50,50,0,0,0,1275,400 L1175,400 A150,150,0,0,1,1175,100 L1406.67,100 L1406.67,200 L1175,200 A50,50,0,0,0,1175,300 L1275,300 A150,150,0,0,1,1275,600 L1043.33,600"/>

<path fill="red" d="M1407.5,600 L1530,180 A125,125,0,0,1,1770,180 L1892.5,600 L1788.33,600 L1674,208 A25,25,0,0,0,1626,208 L1511.67,600" />

</svg>
```

**Rules**

The logo shall be in a single arbitrary colour on a distinctly coloured background.

The accuracy of the logo shall be within +/- 2 units of the specification given in this question.

It is not essential to use the coordinate system used in the specification given in this question. The logo may be rescaled, and different amounts of whitespace may be added above, below, left and right, so long as the logo can be visualized easily with free and easily available software. The logo may not be rotated.

The logo may be drawn filled, or as an outline. The first A and the S overlap slightly. If drawn as an outline, it is preferred that the lines at the overlap of these two letters are omitted, so that the A and S form a single continuous outline. It is however permitted to include the complete outline of the A and/or the complete outline of the S, with the shape specified in the PNG and SVG in the question. No other extraneous lines are permitted.

Any pre-existing graphics format is acceptable provided it can be viewed with free and easily available software. Any means of output accepted by standard rules on this site is acceptable, inlcuding viewing on the screen, output to a file, or (if applicable) as a returned value from a function call. Please Include instructions on how to view your output in your answer. Your program or function should take no input.

It is not acceptable to use a font with letters of the correct or similar shape to print "NASA", with or without modification. (In practice this is unlikely to be an issue, because although there are similar fonts, I think it's very unlikely that the letters match the proportions specified in this question.)

This is codegolf. Shortest code wins.

# Answer
> 10 votes
## SVG (HTML 5), 370 bytes

```
<svg viewbox=0,0,240,64 fill=none stroke=red stroke-width=12.5><path d=M82,62V11M180.4,62V11 transform=skewX(-17) /><path d=M90.8,62V11M189.2,62V11 transform=skewX(17) /><path stroke-width=12 d=M6,62V15.8A9,9,0,0,1,23.6,13.3L34.6,50.7A9,9,0,0,0,52.2,48.2V2M78,13.3a9,9,0,0,1,16.8,0M112,56H139.8a12,12,0,0,0,0,-24h-12A12,12,0,0,1,127.8,8H155.6M176.4,13.3a9,9,0,0,1,16.8,0
```

Based on my optimised answer, but drawing the logo as a stroked path rather than an outline, which takes a few more bytes to set up but requires fewer drawing operations. Edit: Original version was clipped incorrectly. Hopefully this one is nearer to the original.

# Answer
> 5 votes
# HTML / JS, 406 bytes

A RegPack'ed version of the reference SVG with slightly rounded values and uppercase keywords so that the full range `[Y-k]` is available for compression.

```
<script>for(_='5,k00jjLi9k1i5h9k485gi1f1f407,e15d7kc0,bbbab180`jA5b5aa1_,6^,208]jAdbdab1,1[A2k2kabZA12k12ka1,Y<SVG VIEWBOX=a2jb7j><PATH D=M110^f1b2dY35k180L446,492Z4gL4hhgY35b520L259]Z21b2dL210^jM587^i71`Y95`L1072^i968^i854]Z806]L692^jM1043,5f2c5_2c4f1c4[1cee2f1c2_1c3f2c3[275^f043^jM1407^id3`Y177`L1892^f788^f674]Z1626]Ld12^j>';G=/[Y-k]/.exec(_);)with(_.split(G))_=join(shift());document.write(_)</script>
```

# Answer
> 3 votes
# Wolfram Language (Mathematica), 342 bytes

```
a=#~Partition~2&;b=ToCharacterCode;c=Disk;d=Pi/2;e=ArcTan[24/7];Graphics[Thread/@{Cuboid@@@a[2a@b@"ê?êįĦHș?ʾʂ·ʾ{ʂį̍ó"],Parallelogram[a@b@"ĦfɃЌ؛ߤ",a@a@b@"ĒȭĒĨʍĒʍĒĨʍĒʍ"-149],c[f=6a@b@"NINĵN",150,{{d-e,2d},{-d-e,0},g={d-e,d+e},g}],c[h=6a@b@"êÖG",180,a@{-d,d,d,3d}],White,f~c~30,h~c~60}]&

```

Pure function. Takes no input and returns a `Graphics` object as output. In a Mathematica notebook, the output is automatically rendered to the screen. It can be seen in this Wolfram Cloud notebook; a screenshot is shown below.

Some 1-pixel gaps may be visible, but those are just artifacts of the vector graphics. Also, several unprintable characters are used for compression, so here's a UTF-8 hexdump:

```
00000000: 613d 237e 5061 7274 6974 696f 6e7e 3226  a=#~Partition~2&
00000010: 3b62 3d54 6f43 6861 7261 6374 6572 436f  ;b=ToCharacterCo
00000020: 6465 3b63 3d44 6973 6b3b 643d 5069 2f32  de;c=Disk;d=Pi/2
00000030: 3b65 3d41 7263 5461 6e5b 3234 2f37 5d3b  ;e=ArcTan[24/7];
00000040: 4772 6170 6869 6373 5b54 6872 6561 642f  Graphics[Thread/
00000050: 407b 4375 626f 6964 4040 4061 5b32 6140  @{Cuboid@@@a[2a@
00000060: 6240 2203 c3aa 3f03 c3aa c4af c4a6 48c8  b@"...?.......H.
00000070: 993f cabe 03ca 82c2 b7ca be7b ca82 c4af  .?.........{....
00000080: cc8d c3b3 225d 2c50 6172 616c 6c65 6c6f  ...."],Parallelo
00000090: 6772 616d 5b61 4062 4022 c4a6 66c9 8306  gram[a@b@"..f...
000000a0: d08c 06d8 9b06 dfa4 0622 2c61 4061 4062  .........",a@a@b
000000b0: 4022 c492 c295 1ec8 adc4 92c2 95c4 a8ca  @"..............
000000c0: 8dc4 92c2 9502 ca8d c492 c295 c4a8 ca8d  ................
000000d0: c492 c295 02ca 8d22 2d31 3439 5d2c 635b  ......."-149],c[
000000e0: 663d 3661 4062 4022 1a4e 4918 c291 4ec4  f=6a@b@".NI...N.
000000f0: b54e 222c 3135 302c 7b7b 642d 652c 3264  .N",150,{{d-e,2d
00000100: 7d2c 7b2d 642d 652c 307d 2c67 3d7b 642d  },{-d-e,0},g={d-
00000110: 652c 642b 657d 2c67 7d5d 2c63 5b68 3d36  e,d+e},g}],c[h=6
00000120: 6140 6240 22c3 aa1f c396 4722 2c31 3830  a@b@".....G",180
00000130: 2c61 407b 2d64 2c64 2c64 2c33 647d 5d2c  ,a@{-d,d,d,3d}],
00000140: 5768 6974 652c 667e 637e 3330 2c68 7e63  White,f~c~30,h~c
00000150: 7e36 307d 5d26                           ~60}]&

```

# Answer
> 2 votes
# PostScript, 325 bytes

Code (compressed version):

```
<</M{moveto}/L{lineto}>>begin 20 setlinewidth 0 50 translate 32 0 M 47 77 15 180 16.3 arcn 94 23 15 196.3 0 arc 109 100 L 126.4 -4.8 M 166 77 15 163.7 16.3 arcn 201.2 10 L 255 30 20 -90 90 arc 235 70 20 -90 90 arcn 281.4 90 L 290.6 -4.8 M 330 77 15 163.7 16.3 arcn 369.4 -4.8 L stroke 1 setgray 110 0 280 -9 rectfill showpage

```

Code (uncompressed version):

```
% define some short-named procedures for later use
<<
  /M {moveto}
  /L {lineto}
>> begin

% to get shorter code we use stroke (with a big linewidth) instead of fill
20 setlinewidth

0 50 translate  %  we need some empty space at the bottom

% draw N
32 0 M
47 77 15 180 16.3 arcn
94 23 15 196.3 0 arc
109 100 L

% draw A
126.4 -4.8 M   % descender will be cut off later
166 77 15 163.7 16.3 arcn
201.2 10 L

% draw S
 % no moveto here, so we get a connected line
255 30 20 -90 90 arc
235 70 20 -90 90 arcn
281.4 90 L

% draw A
290.6 -4.8 M   % descender will be cut off later
330 77 15 163.7 16.3 arcn
369.4 -4.8 L   % descender will be cut off later

stroke

1 setgray  % white
110 0 280 -9 rectfill  % overwrite the excess bottoms of A

showpage

```

Result:

# Answer
> 2 votes
# PostScript, ~~259~~ 249 bytes

```
[/M{moveto}/L{lineto}/a{arcn}/m{77 15 163.7 16.3 a}/c{20 -90 90}>>begin
20 setlinewidth
32 0 M 47 77 15 180 16.3 a 94 23 15 196.3 0 arc 109 100 L
126.4 -4.8 M 166 m 201.2 10 L 255 30 c arc 235 70 c a 281.4 90 L
290.6 -4.8 M 330 m 369.4 -4.8 L
stroke

```

A shortened version of Thomas Fritsch's answer with more defs to save bytes, and flush with the bottom of the page so the final crop could be removed without changing the appearance.

(This should be a comment on Thomas's answer, but I can't comment yet).

# Answer
> 1 votes
## SVG (HTML5), ~~442~~ ~~440~~ 438 bytes

```
<svg viewbox=0,0,240,64><path fill=red d=M13.2,62V15.8A15,15,0,0,1,42.6,11.6L53.5,49a3,3,0,0,0,5.9,-.8V2h12V48.2A15,15,0,0,1,42,52.4L31.1,15a3,3,0,0,0,-5.9,.8V62m45.3,0L85.2,11.6a15,15,0,0,1,28.8,0L128.7,62H116.2L102.5,15a3,3,0,0,0,-5.8,0L83,62M125.2,50H153a6,6,0,0,0,0,-12H141A18,18,0,0,1,141,2H168.8V14H141a6,6,0,0,0,0,12h12A18,18,0,0,1,153,62H125.2m43.7,0L183.6,11.6a15,15,0,0,1,28.8,0L227.1,62H214.6L200.9,15a3,3,0,0,0,-5.8,0L181.4,62
```

Just an optimisation of the SVG given in the question. There's a better way of doing this!

---
Tags: code-golf, graphical-output
---


title: Infinitely many primes

text:
# Question
Title: Infinitely many primes
Since Euclid, we have known that there are infinitely many primes. The argument is by contradiction: If there are only finitely many, let's say \\$p\_1,p\_2,...,p\_n\\$, then surely \\$m:=p\_1\cdot p\_2\cdot...\cdot p\_n+1\\$ is not divisible by any of these primes, so its prime factorization must yield a new prime that was not in the list. So the assumption that only finitely primes exist is false.

Now let's assume that \\$2\\$ is the only prime. The method from above yields \\$2+1=3\\$ as a new (possible) prime. Applying the method again yields \\$2\cdot 3+1=7\\$, and then \\$2\cdot 3\cdot 7+1=43\\$, then \\$2\cdot 3\cdot 7\cdot 43+1=13\cdot 139\\$, so both \\$13\\$ and \\$139\\$ are new primes, etc. In the case where we get a composite number, we just take the least new prime. This results in A000945.

### Challenge

Given a prime \\$p\_1\\$ and an integer \\$n\\$ calculate the \\$n\\$-th term \\$p\_n\\$ of the sequence defined as follows:

$$p\_n := \min(\operatorname{primefactors}(p\_1\cdot p\_2\cdot ... \cdot p\_{n-1} + 1))$$

These sequences are known as *Euclid-Mullin*-sequences.

### Examples

For \\$p\_1 = 2\\$:

```
1 2
2 3
3 7
4 43
5 13
6 53
7 5
8 6221671
9 38709183810571

```

For \\$p\_1 = 5\\$ (A051308):

```
1 5
2 2
3 11
4 3
5 331
6 19
7 199
8 53
9 21888927391

```

For \\$p\_1 = 97\\$ (A051330)

```
1 97
2 2
3 3
4 11
5 19
6 7
7 461
8 719
9 5

```

# Answer
> 10 votes
# JavaScript (ES6),  ~~45~~  44 bytes

Takes input as `(n)(p1)`, where \\$n\\$ is 0-indexed.

```
n=>g=(p,d=2)=>n?~p%d?g(p,d+1):--n?g(p*d):d:p

```

Try it online!

### Commented

```
n =>                // n = 0-based index of the requested term
  g = (             // g is a recursive function taking:
    p,              //   p = current prime product
    d = 2           //   d = current divisor
  ) =>              //
    n ?             // if n is not equal to 0:
      ~p % d ?      //   if d is not a divisor of ~p (i.e. not a divisor of p + 1):
        g(p, d + 1) //     increment d until it is
      :             //   else:
        --n ?       //     decrement n; if it's still not equal to 0:
          g(p * d)  //       do a recursive call with the updated prime product
        :           //     else:
          d         //       stop recursion and return d
    :               // else:
      p             //   don't do any recursion and return p right away

```

# Answer
> 9 votes
# 05AB1E, 6 bytes

This produces and infinite output stream.

```
λλP>fW

```

Try it online! (link includes a slightly modified version, `λ£λP>fW`, which instead outputs the first \\$n\\$ terms)

### Explanation

Very straightforward. Given \\$p\_1\\$ and \\$n\\$, the program does the following:

* Starts with \\$p\_1\\$ as an initial parameter for the infinite stream (which is generated using the first `λ`) and begins a *recursive environment* which generates a new term after each interation and appends it to the stream.
* The second `λ`, now being used *inside* the recursive environment, changes its functionality: Now, it retrieves all previously generated elements (i.e. the list \\$\[\lambda\_0, \lambda\_1, \lambda\_2, \ldots, \lambda\_{n-1}\]\\$), where \\$n\\$ represents the current iteration number.
* The rest is trivial: `P` takes the product (\\$\lambda\_0\lambda\_1\lambda\_2 \cdots \lambda\_{n-1}\\$), `>` adds one to this product, and `fW` retrieves the minimum prime factor.

# Answer
> 6 votes
# , 15 bytes

-10 bytes thanks to miles!

Returning the sequence up to n (zero-indexed) – thanks to @miles

```
(,0({q:)1+*/)^:

```

Try it online!

# , 25 bytes

Returns the `n` th item

```
_2{((],0{[:q:1+*/@])^:[])

```

Try it online!

# Answer
> 5 votes
# Python 2, 56 bytes

```
i=input();k=1
while 1:
 k*=i;print i;i=2
 while~k%i:i+=1

```

Try it online!

---

## Commented

```
i=input() # the initial prime
k=1       # the product of all previous primes
while 1:  # infinite loop
 k*=i     # update the product of primes
 print i  # output the last prime
 i=2      # starting at two ...
 while~k%i: # find the lowest number that divides k+1
  i+=1
            # this our new prime

```

Try it online!

# Answer
> 4 votes
# Jelly, 8 bytes

```
P‘ÆfṂṭµ¡

```

A full program (using zero indexing) accepting \\$P\_0\\$ and \\$n\\$ which prints a Jelly representation of the list of \\$P\_0\\$ to \\$P\_n\\$ inclusive. (As a dyadic Link, with `n=0` we'll be given back an integer, not a list.)

**Try it online!**

### How?

```
P‘ÆfṂṭµ¡ - Link: integer, p0; integer n
      µ¡ - repeat the monadic chain to the left n times, starting with x=p0:
P        -   product of x (p0->p0 or [p0,...,pm]->pm*...*p0)
 ‘       -   increment
  Æf     -   prime factors
    Ṃ    -   minimum
     ṭ   -   tack
         - implicit print

```

# Answer
> 3 votes
# 05AB1E, 8 bytes

```
GDˆ¯P>fß

```

First input is \\$n\\$, second is prime \\$p\\$.

Try it online or very some more test cases (test suite lacks the test cases for \\$n\geq9\\$, because for \\$p=2\\$ and \\$p=5\\$ the builtin `f` takes too long).

**Explanation:**

```
G         # Loop (implicit input) n-1 amount of times:
 Dˆ       #  Add a copy of the number at the top of the stack to the global array
          #  (which will take the second input p implicitly the first iteration)
   ¯      #  Push the entire global array
    P     #  Take the product of this list
     >    #  Increase it by 1
      f   #  Get the prime factors of this number (without counting duplicates)
       ß  #  Pop and only leave the smallest prime factor
          # (after the loop: implicitly output the top of the stack as result)

```

# Answer
> 3 votes
# Japt, ~~12~~ 11 bytes

Struggled to get this one right so may have missed something that can be golfed.

Takes `n` as the first input and `p1`, as a singleton array, as the second. Returns the first `n` terms. Change `h` to `g` to return the `n`th 0-indexed term instead.

```
@Z×Ä k Î}hV

```

Try it

```
@Z×Ä k Î}hV     :Implicit input of integer U=n & array V=[p1]
@               :Function taking an array as an argument via parameter Z
 Z×             :  Reduce Z by multiplication
   Ä            :  Add 1
     k          :  Prime factors
       Î        :  First element
        }       :End function
         hV     :Run that function, passing V as Z, and
                : push the result to V.
                : Repeat until V is of length U

```

# Answer
> 3 votes
# Retina, 56 bytes

```
,|$
$*
"$&"{~`.+¶
$$¶_
)`\b(__+?)\1*$
$.1$*
1A`
.$

\*
,

```

Try it online! Takes input as the number of new terms to add on the first line and the seed term(s) on the second line. Note: Gets very slow since it uses unary factorisation so it needs to create a string of the relevant length. Explanation:

```
,|$
$*

```

Replace the commas in the seed terms with `*`s and append a `*`. This creates a Retina expression for a string of length of the product of the values.

```
"$&"{
)`

```

Repeat the loop the number of times given by the first input.

```
~`.+¶
$$¶_

```

Temporarily replace the number on the first line with a `$` and prepend a `_` to the second line, then evaluate the result as a Retina program, thus appending a string of `_`s of length 1 more than the product of the values.

```
\b(__+?)\1*$
$.1$*

```

Find the smallest nontrivial factor of the number in decimal and append a `*` ready for the next loop.

```
1A`

```

Delete the iteration input.

```
.$

```

Delete the last `*`.

```
\*
,

```

Replace the remaining `*`s with `,`s.

# Answer
> 2 votes
# JavaScript (Node.js), 54 bytes

```
f=(p,n,P=p,F=n=>-~P%n?F(n+1):n)=>--n?f(p=F(2),n,P*p):p

```

Try it online!

**Ungolfed**

```
F=(p,n=2)=>            // Helper function F for finding the smallest prime factor
  p%n                  //   If n (starting at 2) doesn't divide p:
    ?F(n+1)            //     Test n+1 instead
    :n                 //   Otherwise, return n
f=(p,n,P=p)=>          // Main function f:
  --n                  //   Repeat n - 1 times:
    ?f(p=F(P+1),n,P*p) //     Find the next prime factor and update the product
    :p                 //   Return the last prime

```

# Answer
> 2 votes
# bash +GNU coreutils, 89 bytes

```
IFS=\*;n=$1;shift;for((;++i<n;));{ set $@ `factor $["$*+1"]|cut -d\  -f2`;};echo ${@: -1}

```

TIO

# Answer
> 2 votes
# Ruby 2.6, 51 bytes

```
f=->s,n{[s,l=(2..).find{|d|~s%d<1}][n]||f[l*s,n-1]}

```

`(2..)`, the infinite range starting from 2, isn't supported on TIO yet.

This is a recursive function that takes a starting value `s` (can be a prime or composite), returns it when n=0 (edit: note that this means it's zero-indexed), returns the least number `l` that's greater than 1 and divides `-(s+1)` when n=1, and otherwise recurses with `s=l*s` and `n=n-1`.

# Answer
> 2 votes
# APL (Dyalog Extended), 15 bytes

This is a fairly simple implementation of the algorithm which uses Extended's very helpful prime factors builtin, . Try it online!

```
{⍵,⊃⍭1+×/⍵}⍣⎕⊢⎕

```

**Explanation**

```
{⍵,⊃⍭1+×/⍵}⍣⎕⊢⎕

             ⊢⎕  First get the first prime of the sequence S from input.
{         }⍣⎕    Then we repeat the code another input number of times.
     1+×/⍵       We take the product of S and add 1.
    ⍭            Get the prime factors of product(S)+1.
   ⊃             Get the first element, the smallest prime factor of prod(S)+1.
 ⍵,              And append it to S.

```

# Answer
> 1 votes
# Pari/GP, 45 bytes

```
(p,n)->s=p;for(i=2,n,s*=p=divisors(s+1)[2]);p

```

Try it online!

# Answer
> 1 votes
# Stax, 9 bytes

```
é|G╝╓c£¼_

```

Run and debug it

Takes `p<sub>0</sub>` and (zero-indexed) `n` for input. Produces `p<sub>n</sub>`.

# Answer
> 1 votes
# C (gcc), ~~54~~ 53 bytes

```
p;f(x,n){for(p=x;--n;p*=x)for(x=1;~p%++x;);return x;}

```

Try it online!

*-1 byte thanks to ceilingcat*

# Answer
> 1 votes
# Perl 6, ~~33~~ 32 bytes

*-1 byte thanks to nwellnhof*

```
{$_,{1+(2...-+^[*](@_)%%*)}...*}

```

Try it online!

Anonymous code block that takes a number and returns a lazy list.

### Explanation:

```
{                              }  # Anonymous codeblock
                           ...*   # That returns an infinite list
 $_,                              # Starting with the input
    {                     }       # Where each element is
     1+(2...             )          # The first number above 2
                      %%*           # That cleanly divides
               [*](@_)                # The product of all numbers so far
            -+^                       # Plus one

```

# Answer
> 0 votes
# Haskell, 49 bytes

```
g 1
g a b=b:g(a*b)([c|c<-[2..],1>mod(a*b+1)c]!!0)

```

Try it online!

Returns the infinite sequence as a lazy list.

### Explanation:

```
g 1                                            -- Initialise the product as 1
g a b=                                         -- Given the product and the current number
       b:                                      -- Return the current number, followed by
         g                                     -- Recursively calliong the function with
          (a*b)                                -- The new product
               (                             ) -- And get the next number as
                [c|c<-[2..],             ]!!0  -- The first number above 2
                            1>mod       c      -- That cleanly divides
                                 (a*b+1)       -- The product plus one

```

# Answer
> 0 votes
# Husk, 8 bytes

```
!¡ö←p→Π;

```

Try it online!

For input `m`,`n` outputs the `n`-th term in the sequence starting with `m`.

Drop the initial `!` (for 7 bytes) to output the entire infinite sequence (this link selects the first 10 elements from the infinite list).
If both input & output are flexible enough (input: list of just the first term, output: infinite sequence) we could get down to 6 bytes.

---
Tags: code-golf, sequence, integer, primes, factoring
---


# Question
Title: Golf a number bigger than Loader's number
As a follow up to Shortest terminating program whose output size exceeds Graham's number and Golf a number bigger than TREE(3), I present a new challenge.

Loader's number is a very large number, that is kind of hard to explain (since it was itself the result of a code golfing exercise with a flexible goal). There is a definition and explanation here, but for the purposes of self-containment, I will attempt to explain it later in this post as well.

The algorithm Ralph Loader used produces one of the largest numbers of any (computable) algorithm ever written! Indeed, Loader's number is the largest "computable" number on the Googology Wiki. (By "computable" number, they mean a number defined in terms of a computation.) That means that if answer produces a number larger than Loader's number in an interesting way (i.e. not just Loader's number+1), **you could go down in Googology history!** That being said, programs that produce something like Loader's number+1 are definitely valid answers and contenders to this question; just don't expect any fame.

Your job is to create a terminating program that produces a number *larger* than Loader's number. This is , so the shortest program wins!

* You aren't allowed to take input.
* Your program must eventually terminate deterministically but you can assume the machine has infinite memory.
* You may assume your language's number type can hold **any finite value** but need to explain how this exactly works in your language (ex: does a float have infinite precision?)
    + Infinities are not allowed as output.
    + Underflow of a number type throws an exception. It does not wrap around.
* You need to provide an explanation of why your number is so big and an ungolfed version of your code to check if your solution is valid (since there is no computer with enough memory to store Loader's number).

---

So here is an explanation of Loader's number. See http://googology.wikia.com/wiki/Loader%27s\_number and the links therein for more precise details. In particular, it contains a program that produces Loader's number exactly (by definition).

The calculus of constructions is essentially a programming language with very particular properties.

First of all, every syntactically valid program terminates. There are no infinite loops. This will be very useful, because it means that if we run an arbitrary calculus of constructions program, our program will not get stuck. The problem is that this implies the calculus of constructions is not Turing complete.

Second of all, among non-Turing complete languages, it is one of the most powerful. Essentially, if you can prove that a Turing machine will halt on every input, you can program a function in the calculus of constructions that will simulate it. (This does not make it turing complete, because there are halting turing machines that you can not prove are halting.)

Loader's number is essentially a busy beaver number for the calculus of constructions, which is possible to compute since all coc programs terminate.

In particular, loader.c defines a function called `D`. Approximately, `D(x)` iterates over all bit-strings less than `x`, interprets them as a coc programs, runs the syntactically valid ones, and concatenates the results (which will also be bitstrings). It returns this concatenation.

Loader's number is `D(D(D(D(D(99)))))`.

A more readable copy of the code from the googolology wiki

```
int r, a;

P(y,x){return y- ~y<<x;}

Z(x){return r = x % 2 ? 0 : 1 + Z (x / 2 );}

L(x){return x/2 >> Z(x);}

S(v,y,c,t){
   int f = L(t);
   int x = r;
   return f-2 ? f>2 ? f-v ? t-(f>v)*c : y : P(f,P(S(v,y,c,L(x)), S(v+2,t=S(4,13,-4,y),c,Z(x)))) : A(S(v,y,c,L(x)),S(v,y,c,Z(x)));
}

A(y,x){return L(y)-1 ? 5<<P(y,x) : S(4,x,4,Z(r));}

D(x)
{
   int f;
   int d;
   int c=0;
   int t=7;
   int u=14;
   while(x&&D(x-1),(x/=2)%2&&(1)){
      d = L(L(D(x))),
      f = L(r),
      x = L(r),
      c - r||(L(u)||L(r)-f||(x/=2)%2&&(u=S(4,d,4, r),t=A(t,d)),f/2&(x/=2)%2&&(c=P(d,c),t=S(4,13,-4,t),u=S(4,13,-4,u))),
      c&&(x/=2)%2&&(t=P(~u&2|(x/=2)%2&&(u=1<<P(L(c),u)),P(L(c),t)),c=r)
      u/2&(x/=2)%2&&(c=P(t,c),u=S(4,13,-4,t),t=9);
    }
    return a = P( P( t, P( u, P( x, c)) ),a);
}

main(){return D(D(D(D(D(99)))));}

```

# Answer
# JavaScript, D6(9) (~~508~~ ~~501~~ ~~495~~ ~~492~~ ~~487~~ ~~485~~ ~~481~~ ~~478~~ ~~456~~ 452 bytes)

```
_='P6x-~x<<c,Z6r=x&1?0:1+Z@/2.L6x/2>>Z@.S=;t,f=Ft.x=rKf-2?f>2?f-v?t-(f>v)*c:y:Cf,CH(v+2E,#y.Z@BB:A(H;Z@B.A6L@)-1?5<<PM):GE,Z(rND=M=0,O7,Q14K_=@&&D@-1.!1B?(d=FFD@B.f=Fr.x=Fr.c-r||(Fu)||Fr)-f||!QG,d,r.OA(t,dNfIdE.O#t.Q#uB.c&&!OC~u&2|!Q1<<CFc.uNCFc.tNc=r.uItE.Q#t.O9.DM,t,uB:CCt,Cu,PMB._.JJJ9BBB!@>>=1)%2&&(#G-8,13,N)..),6=MK;(vE,y,HS;L@NS@(xB))I/2&!c=CCP(M@EE,cFL(GS(4,4JD(D(K)=>Ot=Qu=';for($ of'QOKJGFEMCIB@H;6.N#!')with(_.split($))_=join(pop());eval(_)

```

This is an encoded code.

```
_='P6x-~x<<c,Z6r=x&1?0:1+Z@/2.L6x/2>>Z@.S=;t,f=Ft.x=rKf-2?f>2?f-v?t-(f>v)*c:y:Cf,CH(v+2E,#y.Z@BB:A(H;Z@B.A6L@)-1?5<<PM):GE,Z(rND=M=0,O7,Q14K_=@&&D@-1.!1B?(d=FFD@B.f=Fr.x=Fr.c-r||(Fu)||Fr)-f||!QG,d,r.OA(t,dNfIdE.O#t.Q#uB.c&&!OC~u&2|!Q1<<CFc.uNCFc.tNc=r.uItE.Q#t.O9.DM,t,uB:CCt,Cu,PMB._.JJJ9BBB!@>>=1)%2&&(#G-8,13,N)..),6=MK;(vE,y,HS;L@NS@(xB))I/2&!c=CCP(M@EE,cFL(GS(4,4JD(D(K)=>Ot=Qu='; //encoded code
for($ of'QOKJGFEMCIB@H;6.N#!')with(_.split($))_=join(pop()); //decoding
eval(_) //Evaluation of the string

```

Decoded code:

```
P=(x,c)=>x-~x<<c,Z=(x,c)=>r=x&1?0:1+Z(x/2),L=(x,c)=>x/2>>Z(x),S=(v,c,y,t,f=L(t),x=r)=>f-2?f>2?f-v?t-(f>v)*c:y:P(f,P(S(v,c,y,L(x)),S(v+2,c,S(4,4-8,13,y),Z(x)))):A(S(v,c,y,L(x)),S(v,c,y,Z(x))),A=(x,c)=>L(x)-1?5<<P(x,c):S(4,4,c,Z(r)),D=(x,c=0,t=7,u=14)=>_=(x&&D(x-1),(x>>=1)%2&&(1))?(d=L(L(D(x))),f=L(r),x=L(r),c-r||(L(u)||L(r)-f||(x>>=1)%2&&(u=S(4,4,d,r),t=A(t,d)),f/2&(x>>=1)%2&&(c=P(d,c),t=S(4,4-8,13,t),u=S(4,4-8,13,u))),c&&(x>>=1)%2&&(t=P(~u&2|(x>>=1)%2&&(u=1<<P(L(c),u)),P(L(c),t)),c=r),u/2&(x>>=1)%2&&(c=P(t,c),u=S(4,4-8,13,t),t=9),D(x,c,t,u)):P(P(t,P(u,P(x,c))),_),D(D(D(D(D(D(9))))))
// We also have _ equal to the code itself.

```

The logic is the same as the original loader.c, but few non-critical modifications are made to compress the code better.

In this, it is assumed to be:

* Infinite call stack
* Infinite memory
* Infinite precision `Number`
* Infinite magnitude `Number`
* Bitshift and bitwise operators work on infinite bit integers instead of 53 bits. Bitwise negation still negates the sign bit.

## Encoding/Decoding algorithm:

The encoding is done as follows:

* Take a repeated string, call it S.
* Replace all S in the code to a key K.
* Put K and S at the end.
* Make a list of keys, and also put decoding algorithm so the code actually runs.

The decoding algorithm:

* Take list of keys.
* Take the earliest key K.
* Split the string for each K.
* Since last of the array is what to replace K S, pop it, and replace all K by joining the array with the popped value S.

The compression was done with this code.

(d=String.fromCharCode)((c=a.charCodeAt())\>\>8)+d(c&255)).join\`\`.slice(1)) \`\`\` This code will take the 16bit string as a, converts it to 8bit string with same binary(BE), and \`eval\` it. The decoded code is the encoded code above. --\>

## Proof that D6(9)\>D5(99)

For this, we would compare D(0) and 99. We find that D(0) is equal to `8646911284551352321` (note that in a normal environment without modifications we won't get a correct result because the higher bits are truncated). So, D(0)\>99, and since D is strictly increasing, D6(9)\>D6(0)\>D5(99).

* 508B-\>501B, -7B
    + -1B for... I don't know why. I did change `D(D(D(D(D(99)))))` to `D(D(D(D(D(D(9))))))`. Also that shuffled the letters.
    + -6B for re-adding `&&(1)` for `D(x)`'s loop condition.
* 501B-\>495B, -6B
    + Fixed most `/2`s to `>>1`s because `Number`
    + 6 bytes saved from somewhere
    + You can see my attempt in this update here
* 495-\>492B, -3B
    + By changing the decoder from `for...in` to `for...of`.
* 492-\>487B, -5B
    + Removing unnecessary assignments
    + Changing argument names
* 487-\>485B, -2B
    + 1 byte from using `eval` for `D`, removing `return`.
    + 1 byte compression combining the closing parentheses to a comma.
* 485-\>481B, -4B
    + By compressing different substrings.
* 481-\>478B, -3B
    + Removed unnecessary variable assignment.
* 478-\>456B, -22B
    + You can find me posting updates at *Googology Server!* (Discord).
    + 2 bytes from changing from D6(9) to D6(0).
    + 1 byte from making `D` recursive instead of using a loop.
    + 7 bytes from making `f` and `d` in `D` global and not declaring them. It works since they are reassigned every time going through the loop, and `D` is not called between the assignment and the next iteration.
    + 2 bytes from removing assignment to `r`. They will be assigned before use.
    + 1 byte from removing an unnecessary assignment corresponding here in the original code. It no longer saved bytes.
    + 1 byte from fixing a typo. I still don't know how it appeared.
    + 2 bytes from swapping the second and the third variable of `S`. I checked and it should work fine.
    + 1 byte from changing instances of `S(4,-4,13,` to `S(4,4-8,13,`.
    + 2 bytes from adding unused variables `y` to `Z` and `L`.
    + 1 byte from changing `Z`.
    + 2 bytes from reusing `_` as the accumulator. It starts out as a `String` containing the decoded code, and in such a case, it acts as `0` in bitwise operators. Also changed back to D6(9) for good measure.
* 456-\>452B -4B
    + Changed the 1-argument and 2-arguments functions' argument names to `(x,c)`.
> 13 votes

# Answer
# Python, q^15(2) = q^13(5), 319 bytes

This is my first time submitting a program to code golf, but certainly not my first time implementing or inventing a large number. I probably won't go down in googology history for this. Anyway, here is my program, the explanation comes later:

```
_="78b/:!if b==1:&(a+1)%c!9&s(8b-1/,s(81///\n7f(a):!m=[]*True:!#for x in range(65536):!##if a(x)==a(x+k): break!##9 pass'p = 4x:f(4y:s(1,y,x))\n7q(a):*p(k)<2^a:'k = $$$$$2...!\n##    $q(q(q('!#k+=1!&k\n&return *!k=0!while .)))))/,c)4lambda 7def 8s(a,9else:"
for Y in"9874/.*&'$#!":_=_.split(Y);_=_.pop().join(_)
exec(_)

```

I compressed this code using the same tool which Naruyoko used, here. Here is the uncompressed form:

```
def s(a,b,c):
    if b==1:return (a+1)%c
    else:return s(s(a,b-1,c),s(s(a,1,c),c),c)
def f(a):
    m=[]
    k=0
    while True:
        for x in range(65536):
            if a(x)==a(x+k): break
            else: pass
        k+=1
    return k
p = lambda x:f(lambda y:s(1,y,x))
def q(a):
    k=0
    while p(k)<2^a:
        k+=1
    return k
k = q(q(q(q(q(q(q(q(q(q(q(q(q(q(q(2)))))))))))))))

```

## Explanation

I had a hard time choosing what to use. I was originally planning to implement my LINEAR(k) function, which I might do another time, but I didn't know if it would produce large enough numbers, and it would be hard to implement, so my next choice was greedy clique sequences, but those didn't work either, so I just ended up using Laver tables.

So, how do Laver tables work? Well the size-n Laver table is a binary operator ab, with the following rules: a0=0, a1=a+1 mod n and ab=(a(b-1))(a1) for b\>1. p(n) is defined as the period of the function 1a, which is quite slow-growing.

The first few values of p(n) are 1,1,2,4,4,8,8,8,8,16,16,16,16,... Then q(n) is the least integer so that p(q(n)) is greater than or equal to 2^n. This is very fast-growing, and its totality can only be proven in ZFC+I3, so one could approximate it to f\_PTO(ZFC+I3)(n) in FGH, although this doesn't work since there is no system of fundamental sequences associated to PTO(ZFC+I3).

The first few values of q(n) are 0,2,3,5,9. q(5) is approximated to Ack(9,Ack(8,Ack(8,255))) using the Ackermann function, and q(6) is believed to be greater than Graham's number!

So, now that we know how Laver tables work, how does my code work? Well, s(a,b,c) denotes the operator ab where n=c, then the function f(a) uses complex while loops to find the period of the given function a.

p is represented by the lambda which returns `f(lambda y:s(1,y,x))`, i.e. the period of `s(1,y,x)` where x is the input to p. q then just uses for loops to find the least integer k s.t. p(k) =\> 2^a.

My code then returns q^13(5), which has been proven to be greater than f\_w(f\_w+1(5)); note that this was for q^13(1) but q is strictly increasing so this also acts as a lower bound for q^13(5). This lower bound however is a severe understatement, since, as I mentioned earlier, q(n) cannot be proven total in ZFC while f\_w(f\_w+1(5)) can be by FAR.

Similarly, this code should return a number greater than Loader's number since, although sadly there is no proof, Loader's function is commonly believed to be provably total in ZFC; I do note however that just because a function which is provably total in a stronger theory doesn't mean that it will eventually dominate the one provably total in the weaker theory. It is usually the case though. So, all said, I WIN!!!

Edit: I lose because the code is completely broken and I can't fix it...
> 7 votes

# Answer
# Python, q15(2), 192 bytes

```
def q(k,c=0,n=0):
 while c*2<1<<k:
  n+=1;*x,=map(s:=lambda b,a=1:s(a,s(b-1,a))if a*b else(a-~b)%c,range(c:=1<<n))
  while x[:c]==x[-c:]:x=x[:c];c>>=1
 return n
print(eval(15*'q('+'2'+')'*15))

```

See Binary198's answer for the definition of q and an argument that q15(2) is large enough. If the argument is correct, then this is an impressively concise way to beat Loader's number. Unfortunately their implementation is broken.

This is my attempt at reasonably well golfed code that, I think, actually works. At least, it correctly computes values of q up to q(3)=5. (If you want to test that, you should wrap the definition of `s` in `functools.lru_cache(None)(...)`.) Computing q(4)=9 may be possible, but will need a lot of stack space.

s(b,a) computes row a, column b+1 of the Laver table of size c, using 0...c-1 as the representatives of Z/cZ instead of the usual (for these tables) 1...c. The period-finding code uses the fact that the period can only be a power of 2. Other than that, there are only standard golfing tricks here.

I deliberately computed the same value as Binary198's answer, though it could be made larger at no cost, because I'm not trying to compete on size; I just wanted a working implementation of this interesting function (for some definition of "working").
> 4 votes

# Answer
# Ruby, D6(9) (~~553~~ ~~544~~ ~~535~~ ~~516~~ ~~511~~ 507 bytes)

```
_='a=r=0;P"x-~x<<y};Z"r=x%2B1?0M1+J/2FL"x/2>>JFS=->vEt{f=L(t);x=r;fB2?A*EJ6Mf>2?fBv ?yMf>v ?t-cMtM@f,P*+2,#y8c,J6FA"Cx]B1?Ky,4,Z[r]]M5<<@x,yFD"f=d=c=0;t=7;O14;while[xIHx-18.>0][1];d=CCHx6;f=N;x=N;cBr&&[Cu]B0&&NBf&&.I[OKd,4,rQA[t,d]8fGd,cQ#t8O#u6;cI.&&[t=@~u&2|.I(O1<<@Cc8u]),@Cc8t]8c=r];uGt,c8O#tQ9];end;a=@@t,@u,@x,c6,aF$><<HHHHHH966"=->x,y=0{#K13,-4,*[S[vECx]8S[v.(x/=2)%26]]]8],@P[B==CL[E,y,c,F]};G/2&.I[c=@HD[IB0||JZ[xKS[4,M: NCr]Ou=Q8t=';'QONMKJIHGFECB@86.*#"'.each_char{|y|*_,y=_.split y;_=_*y};eval _

```

This is an encoded code. Extracted:

```
a=r=0;P=->x,y=0{x-~x<<y};Z=->x,y=0{r=x%2==1?0: 1+Z[x/2]};L=->x,y=0{x/2>>Z[x]};S=->v,y,c,t{f=L(t);x=r;f==2?A[S[v,y,c,L[x]],S[v,y,c,Z[x]]]: f>2?f==v ?y: f>v ?t-c: t: P[f,P[S[v,y,c,L[x]],S[v+2,S[4,13,-4,y],c,Z[x]]]]};A=->x,y=0{L[x]==1?S[4,y,4,Z[r]]: 5<<P[x,y]};D=->x,y=0{f=d=c=0;t=7;u=14;while[x==0||D[x-1],(x/=2)%2>0][1];d=L[L[D[x]]];f=L[r];x=L[r];c==r&&[L[u]==0&&L[r]==f&&(x/=2)%2==0||[u=S[4,d,4,r],t=A[t,d]],f/2&(x/=2)%2==0||[c=P[d,c],t=S[4,13,-4,t],u=S[4,13,-4,u]]];c==0||(x/=2)%2&&[t=P[~u&2|(x/=2)%2==0||(u=1<<P[L[c],u]),P[L[c],t]],c=r];u/2&(x/=2)%2==0||[c=P[t,c],u=S[4,13,-4,t],t=9];end;a=P[P[t,P[u,P[x,c]]],a]};$><<D[D[D[D[D[D[9]]]]]]

```

This code is Loader's Number with D6(9) instead.

In this, it is assumed to be:

* Infinite call stack
* Infinite memory

This is basically a port of my JavaScript answer and Python 3 answer. For more details, check those.

The compression was done with this.

I am a beginner at Ruby, so maybe under 512 is possible, but I doubt it.

* 553-\>544B, -9B
    + Added 3 bytes from fixing a formatting error.
    + 5 bytes from removing an unused print.
    + 4 bytes from changing expression `t-(f>v ?1: 0)*c` to `f>v ?t-c: t`
    + 1 byte from removing an unnecessary assignment to `t`.
    + 2 bytes from removing an assignment to `r`.
* 544-\>535B, -9B
    + Improved the decoder.
* 535-\>516B, -19B
    + 17 bytes from changing functions to lambda expressions.
    + 1 byte each from removing parenthesis from `split` and `eval`.
    + Thanks @Dom Hastings!
* 516-\>511B, -5B
    + Use `a` and `r` declared globally, instead of `$a` and `$a`.
* 511-\>507B, -4B
    + Change all 1 and 2 argument functions' arguments to `x,y=0`.
> 3 votes

# Answer
# Python, 498 bytes, ???

I don't know how large this program would get.

Okay, I've had a few failed attempts on this, but I think I've got it this time. First, the code:

```
from itertools import product as X
C=[1,0]
V=[9]
r=range
L=list
def R(n):
    C[0]=1
    while C[0]:
        C[0]=0
        for m in r(V[0]):P(m,n)
        if(C[0]<1)+(C[1]<len(V)):P(C[1],n,1)
    return sum(V)
def P(m,n,B=0,T=0):
    if m==len(V):V.append(0)
    k=m+n;c=r(k)
    for M in X(*[L(X(*[L(X(c,c,[-1,0,1]))]*k))]*k):
        t={};u=p=s=d=1
        while d:
            s,c,d=M[s][t.get(p,0)];t[p]=c;p+=d;u+=1
            if u>sum(V):u=d=0
        T+=u
    if T>V[m]:C[0]=V[m]=T;C[1]=min(C[1],m+1)
    if B>C[0]:V[m]+=1;P(m,n,1)
z=9**9
exec("z=R(z);"*R(z))
print(z)

```

# Explanation:

This function simulates all Turing machines with n states and n colours for a number of steps (initially 9), then sums the number of steps that it took for any machine that halted to halt, storing that value as the number of steps to take on the next iteration. It keeps doing this until it reaches a steady state.

We don't just look at machines that have n states and colours, but also n+1, n+2, up to n+V\[0\], where V\[0\] is the sum of the halting times for the machines with n states and colours.

So far, I've just described a function which is polynomial at best. Notably, it grows slower than the busy beaver function on these Turing machines. Thus, we can be confident that there is at least one machine of size n which halts but we have not yet found. So we search for that one (this function is undefined on inputs which are too small).

Once we find it, we continue on as we were. We'll reach another steady state. This time, we can't be confident that there is another halting Turing machine of size n, but as BB(n+1)\>F(BB(n)) for any reasonable polynomial function F (which this is), we can be confident that there is a halting Turing machine of size n+1 which we have not found. If we then find a halting machine of size n, we know that we can perform this step on n+1 again.

We repeat this process until we've attempted this on every size of machine we're looking at (from n to n+V\[0\]), and thus can no longer be confident that there is a machine that halts of those sizes that we have not seen.

While this number is certainly less than BB(n), I'm not sure how one would go about determining just how big it is. The guarantee that it halts is basically "BB(n) grows much faster than this does". I'm fairly confident that's a safe assumption for values of `R(n)` greater than, say, `R(5)`.

Here's a less golfed version with comments:

```
from itertools import product as X
 # C[0] is 1 or 0 representing a change, so keep looping
 # C[1] is the next machine that needs to search.
C=[1,0]
 # V[x] is the total steps taken by the machine with n+x colours and states
V=[9]
def R(n):
    while C[0]:
        C[0]=0
        # Run each set of machines sum(V) steps.
        for m in range(V[0]):P(m,n)
        # Run machine set C[1] sum(V) steps, then run it until one more machine stops.
        if C[0]<1 and C[1]<len(V):P(C[1],n,1)
    return sum(V)
 # Run one set of machines with m+n colours and states.
def P(m,n,B=0):
    if m==len(V):V.append(0)
    # Start our total at 0
    T=0
    # For each machine in the set...
    for M in G(m+n):
        # Step count u starts at 0
        # The tape t starts empty
        # Position p starts at 1
        # State s starts at 1
        # Direction d starts at 1.  These are all 1 because it's shorter and we use d=0 as break
        t={};u=p=s=d=1
        while d:
            s,c,d=M[s][t.get(p,0)];t[p]=c;p+=d;u+=1
            if u>sum(V):u=d=0
        T+=u
    # If the total is greater than the last time we ran this set, increase it and note there's been a change
    if T>V[m]:
        C[0]=V[m]=T
        if m<C[1]:C[1]=m+1
    # If we're running it until there's a change, increment V[m] and try again.
    if B>C[0]:V[m]+=1;P(m,n,1)
 # Generate all the machines of appropriate size.
def G(k):
    L=list
    # List of colours
    c=range(k)
    # List of options for a single state/colour combination - new state, colour written, direction moved (0 being halt)
    O=L(X(c,c,[-1,0,1]))
    # List of options for one state
    S=L(X(*[O]*k))
    # List of options for all states
    return L(X(*[S]*k))
r=9**9
for i in range(R(r)):
    # Reset C[0], as we need to be able to run again.  C[1] will get reset in P().
    C[0]=1;r=R(r)
print(r)

```

Actually, it occurs to me that there's no reason why (in principle) we can know that `R(n) < BB(n)` (when `BB(n)` is defined to be on Turing machines with n colours and states). Determining exactly how big `R(n)` is is related to a limited version of the halting problem, as it isn't guaranteed that $$BB(n)\*2^{n\*2^{3n^2}}\<BB(n+1)$$ That's the limit on how quickly `R(n)` grows without the "look for the next terminating machine" step. I think it's a pretty safe assumption, though, that it's true with `n>5` or so.

while we can know that `R(n)` halts on big enough inputs, it's certainly possible that the result is in every case larger than `BB(n)`. Proving such (if true) would be equivalent to the halting problem, of course.
> 3 votes

# Answer
# Python 3, D^6(9) (~~608~~ ~~600~~ ~~599~~ ~~597~~ ~~591~~ ~~583~~ 573 bytes)

```
_="a=06PJ$x-~x<<c6ZJr=0'E?1+TKQ$r6LJ$xK+T)6@t!YtUr#$A([@TC)'f==2?If,I[S(v+2R,/yUTCC'f<2?t-(f>v)*c'f-v?y6AJ$5<<PB)'Fx)-1?MR,Z(rC6DB=0,t=7,X14!Gx:Nx-1Q.G~EV a=IIt,Iu,PBCUaQ $a#d,YFNxCUFrUFrQGc-rV'not(Fu)or(Fr)-fCH'E:XM,d,rOA(t,dQ'fKH'WdRO/t);X/uQGcV .'EH q=~u&2|E# 'q:X1<<IFuUuQ  tR=Iu'q?q,IFcUtC,r#.GuK&WtR);X/tO9#$DB,t,u)\nprint(NNNNNN9CCC)!)Vglobal r,a##\n $return ' G.x=xK#/M-8,13,6\ndef ? else @S(vR,y,B(xRC))Ex%2FL(Gif HV  . IP(JB=0!K>>1MS(4,4ND(O);t=Q)#R,cTZ(xU),V:#WE:c=IXu=Yf,x=F[@FxC,"
for Y in"[YXWVUTRQONMKJIHGFECB@?6/.'$#!":_=_.split(Y);_=_.pop().join(_)
exec(_)

```

This is an encoded code. Extracted:

```
a=0
def P(x,c=0):
 global r,a
 return x-~x<<c
def Z(x,c=0):
 global r,a
 r=0 if x%2 else 1+Z(x>>1)
 return r
def L(x,c=0):
 global r,a
 return x>>1+Z(x)
def S(v,c,y,t):
 global r,a
 f,x=L(t),r
 return A(S(v,c,y,L(x)),S(v,c,y,Z(x))) if f==2 else P(f,P(S(v,c,y,L(x)),S(v+2,c,S(4,4-8,13,y),Z(x)))) if f<2 else t-(f>v)*c if f-v else y
def A(x,c=0):
 global r,a
 return 5<<P(x,c) if L(x)-1 else S(4,4,c,Z(r))
def D(x,c=0,t=7,u=14):
 global r,a
 if x:D(x-1)
 x=x>>1
 if ~x%2:
  a=P(P(t,P(u,P(x,c))),a)
  return a
 d,f,x=L(L(D(x))),L(r),L(r)
 if c-r:
  if not(L(u)or(L(r)-f)):
   x=x>>1
   if x%2:u=S(4,4,d,r);t=A(t,d)
  if f>>1:
   x=x>>1
   if x%2:c=P(d,c);t=S(4,4-8,13,t);u=S(4,4-8,13,u)
 if c:
  x=x>>1
  if x%2:
   x=x>>1
   q=~u&2|x%2
   if q:u=1<<P(L(u),u)
   t,c=P(u if q else q,P(L(c),t)),r
 x=x>>1
 if u>>1&x%2:c=P(t,c);u=S(4,4-8,13,t);t=9
 return D(x,c,t,u)
print(D(D(D(D(D(D(9)))))))

```

In this, it is assumed to be:

* Infinite call stack
* Infinite memory

This is basically a port of my JavaScript answer. For more details, check that one.

The compression was done with this.

I am not very knowledgeable in Python, so there are certainly places to save bytes. ~~I think sub-600 is possible.~~ sub-600 has been proven.

* 608-\>600B, -8B
    + Grouped some assignments
    + Reversed conditions of `S` to reduce parenthesis
* 600-\>599B, -1B
    + Changing `u/2` in the third last line of the definition of `D` to `u>>1`, saving a byte from compressing it to a character with other `>>1`s.
* 599-\>597B, -2B
    + 2 bytes from removing assignment to `r`.
* 597-\>591B, -6B
    + Made `D` recursive.
    + Removed the unnecessary assignments to `d`, `f`, and `c`. Making `D` recursive allows this to be completely removed and save more bytes whereas keeping it in a loop would have still needed an assignment to `c`.
* 591-\>583B, -8B
    + Changed the 1-argument and 2-arguments functions' arguments to `(x,c=0)`.
    + Added `global r,a` to every function.
    + Swapped the second and the third of `S`.
    + Changed the instances of `S(4,-4,13,` to `S(4,4-8,13,`.
    + Fixed the compression algorithm (specifically displaying) so it actually works now.
* 583-\>573B, -10B
    + Replaces `q and u` with `u if q else q` and that somehow saved 10 bytes.
> 2 votes

---
Tags: code-golf, math, number, busy-beaver, open-ended-function
---


title: Fibonacci-orial

text:
# Question
Title: Fibonacci-orial
# 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

# Answer
> 71 votes
## Mathematica, 10 bytes

```
Fibonorial

```

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

# Answer
> 28 votes
# 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.

```

# Answer
> 21 votes
# 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!.

# Answer
> 21 votes
## 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.

# Answer
> 15 votes
## 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

```

# Answer
> 13 votes
## 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.

# Answer
> 11 votes
# Python 2, 39 bytes

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

```

Test it on Ideone.

# Answer
> 6 votes
# 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

```

# Answer
> 4 votes
# 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.

# Answer
> 4 votes
# 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}

```

# Answer
> 4 votes
# 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

```

# Answer
> 4 votes
# 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

# Answer
> 4 votes
# 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)
}

```

# Answer
> 3 votes
## 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)

```

# Answer
> 3 votes
# Brachylog, 31 bytes

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

```

Try it online!

# Answer
> 3 votes
# APL (Dyalog Unicode), 18 bytes

```
×/(+.!∘⌽⍨∘⍳¨1+∘⍳⊢)

```

Explanation:

```
×/(+.!∘⌽⍨∘⍳¨1+∘⍳⊢)
            1+∘⍳⊢   ⍝ generate numbers 2-(⍵+1)
           ¨        ⍝ ... map to each
   +.!∘⌽⍨∘⍳         ⍝ n-th fibonacci number
×/                  ⍝ product of all

```

Fibonacci formula explanation:

```
+.!∘⌽⍨∘⍳
       ⍳    ⍝ numbers 1 to ⍵
     ⍨      ⍝ apply to both sides of +.!∘⌽
    ⌽       ⍝ reverse the ⍵ vector.
+.!         ⍝ inner product: sum and binomial

```

Try it online!

# Answer
> 2 votes
# 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.**

# Answer
> 2 votes
# Ruby, 39 bytes

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

```

# Answer
> 2 votes
# 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

```

# Answer
> 2 votes
# 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**

# Answer
> 2 votes
# 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

```

# Answer
> 2 votes
# 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

# Answer
> 2 votes
# 05AB1E, ~~6~~ 4 bytes

```
LÅfP

```

Try it online!

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

# Answer
> 2 votes
# 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.

# Answer
> 2 votes
# Brain-Flak, 54 bytes

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

```

Try it online!

Multiplication in Brain-Flak takes a long time for large inputs. Just multiplying F<sub>100</sub> by F<sub>99</sub> 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 compute`n` 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!

# Answer
> 2 votes
# tinylisp, ~~83~~ 81 bytes

```
(load library
(d F(q((N)(i(l N 3)1(a(F(s N 1))(F(s N 2
(d P(q((N)(product(map F(0to N

```

Try it online!

-2 bytes thanks to DLosc for reminding me to remove parentheses.

# tinylisp, 108 bytes

```
(d F(q((N)(i(l N 3)1(a(F(s N 1))(F(s N 2
(d M(q((A B)(i A(a B(M(s A 1)B))0
(d P(q((N)(i N(M(F N)(P(s N 1)))1

```

Try it online!

Exceeds the maximum recursion depth around `N=14`.

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
## Mathematica - 32 26 bytes

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

```

@MartinEnder chopped 6 bytes!

# Answer
> 1 votes
## GAP 28 Bytes

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

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

```

# Answer
> 1 votes
### 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

# Answer
> 1 votes
# Julia, 36 bytes

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

```

# Answer
> 1 votes
# 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)`.

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
## 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)))

```

# Answer
> 1 votes
# 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)}

```

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
## 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

```

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
# 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!

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
# 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.

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
# Whispers v3, 43 bytes

```
> Input
> fₙ
>> 2ᶠ1
>> ∏3
>> Output 4

```

Try it repl.it!

Needs to be run with

```
python3 whispers\ v3.py fibonacciorial.wisp < input.txt 2> /dev/null

```

Finishes well within 5 seconds on repl.it.

# Answer
> 1 votes
# Setanta, ~~65~~ 62 bytes

```
gniomh(n){a:=0b:=1x:=1le i idir(0,n){b+=a a=b-a x*=a}toradh x}

```

Unfortunately isn't exact because this language doesn't have bigints.

Try it here!

# Answer
> 1 votes
# Tcl, 110 bytes

```
set a 0
set b [incr x]
time {set c [expr $a+$b]
set a $b
set x [expr $x*[set b $c]]} [expr {*}$argv-1]
puts $x

```

Try it online!

Was able to take off 9 bytes thanks to sergiol!

# Answer
> 1 votes
# Tcl, 115 bytes

```
proc F x {expr $x>1?\[F $x-1]+\[F $x-2]:$x}
proc P x {incr p
while {[incr i]<=$x} {set p [expr $p*[F $i]]}
expr $p}

```

Try it online!

# Answer
> 1 votes
# Vyxal, 7 bytes

```
ƛÞF$i;Π

```

Try it Online!

# Vyxal `r`, 6 bytes

```
ƛÞFi;Π

```

Try it Online!

```
        # implicit input
ƛ    ;  # Lambda map (1...input inclusive)
 ÞF     # All fibbonacci numbers
   $    # Swap stack
    i   # Item
      Π # Reduce by product
        # Implicit output

```

With r, all functions take arguments in reverse, so `$` is not needed.

# Answer
> 1 votes
# Vyxal, 4 bytes

```
ÞFẎΠ

```

Try it Online!

Come on Vyxal, you can do better.

```
ÞFẎΠ # Takes a number input
ÞF   # Infinite Fibonacci numbers
  Ẏ  # Limit to first n numbers
   Π # Product of them

```

# Answer
> 0 votes
# 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

```
{}

```

# Answer
> 0 votes
## Pyke, ~~6~~ 5 bytes

```
Sm.bB

```

Try it here!

```
product(map(nth_fib, input))

```

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
## 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 `1`s, 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

```

# Answer
> 0 votes
## 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

# Answer
> 0 votes
# 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!**

# Answer
> 0 votes
## 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.

# Answer
> 0 votes
# 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.

```

# Answer
> 0 votes
# R, ~~36~~ 34 bytes

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

```

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

# Answer
> 0 votes
# Javascript, 44 bytes

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

```

based on this Fibbonaci sequence

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
# 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)

# Answer
> 0 votes
# Jelly, 4 bytes

```
RÆḞP

```

Try it online!

**Explanation**

```
R       inclusive range
 ÆḞ     nth fibonacci number
   P    product

```

# Answer
> 0 votes
# Japt, 7 bytes

```
õ@MgXÃ×

```

Try it

---

## Explanation

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

```

# Answer
> 0 votes
# 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)))

```

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
# Charcoal, 28 bytes

```
≔¹α≔¹β≔¹χＦＮ«≔×χαχ≔βα≔⁺αββ»Ｉχ

```

Try it online!

# Answer
> 0 votes
# Factor \+ `math.unicode`, 43 bytes

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

```

Try it online!

# Answer
> 0 votes
# 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)

```

---
Tags: code-golf, math, sequence, fibonacci, restricted-time
---