25
\$\begingroup\$

This question was reworked, please re-read it.

Ultrafactorials

The ultrafactorials are a sequence of numbers which can be generated using the following function:

a(n) = n! ^ n!

The resulting values rise extremely quickly. Side note: This is entry A046882 in the OEIS. Also related are the hyperfactorials, a still quite huge, but a bit smaller sequence: A002109

Your task

Your task is to implement these numbers into your language. Your program will calculate the sum of all ultrafactorials from 0 up to inclusive n.

Input

Your program may only take one input: a number, which resembles the last a(n) ultrafactorial to be added to the sum. The Input is assured to be positive or 0.

Output

Your output is all up to you, as long as there's the visible sum of the numbers somewhere.

Rules

  • You can assume all integers, therefore integer input, and using integer counting loops to produce some results.

Test cases

Input: -1
Output: Any kind of error (because -1! is undefined), or no handling at all

Input: 0
Output: 1

Input: 1
Output: 2

Input: 2
Output: 6

Input: 3
Output: 46662

Challenge

This is , so the answer with the least length in bytes wins!

\$\endgroup\$
  • 2
    \$\begingroup\$ Do we need to consider arbitrarily large integers? Or is it enough to handle the largest that the language's default data type (such as double) supports ? \$\endgroup\$ – Luis Mendo Dec 19 '16 at 22:46
  • 1
    \$\begingroup\$ The conversion in-code and output is up to you, the Input will be an integer though. @LuisMendo \$\endgroup\$ – devRicher Dec 19 '16 at 22:51
  • 3
    \$\begingroup\$ Changing the rules after many people have answered isn't a nice thing to do either. Please use the Sandbox as advised whenever you want to submit a challenge. \$\endgroup\$ – flawr Dec 20 '16 at 9:46

36 Answers 36

1
2
0
\$\begingroup\$

Actually 11 10 bytes

1+r`!;ⁿ`MΣ

How it works

Program takes implicit input, implicit print at EOF
1+          Add one to the input n+1
  r         Create a range (0,1,..,n)
   `   `    Create a function between the two `
    !       Factorialize the current stack item
     ;      Duplicate the current stack item
      ⁿ     Power a,b from the current stack item
         M  Map the function across the stack top item
          Σ Sum the stack together
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Racket 54 bytes

(for/sum((i(+ 1 n)))(let((t(factorial i)))(expt t t)))

Ungolfed:

#lang racket
(require math)

(define (f n)
  (for/sum ((i (+ 1 n)))
    (let ((t (factorial i)))
      (expt t t))))

Testing:

(f -1)
(f 0)
(f 1)
(f 2)
(f 3)

Output:

0
1
2
6
46662
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog), 11 bytes

+/(*⍨∘!0,⍳)

Try it online!


This function train is equivalent to {+/*⍨!0,⍳⍵}, which is a straight forward implementation

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Japt, 8 6 bytes

òÊx_pZ

Test it


Explantion

Implicit input of integer U
3

ò

Create an array of integers from 0 to U, inclusive.
[0,1,2,3]

Ê

Get the factorial of each integer in the array.
[1,1,2,6]

_

Map over the array.

pZ

Raise each element (p) to the power of itself (Z).
[1,1,4,46656]

x

Reduce by addition and implicitly output the result.
46662

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Perl 6, 38 bytes

{[+] map {my \a=[*] 1..$_;a**a},0..$_}

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 8 bytes

ƒN!N!m}O

Try it online!

| improve this answer | |
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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