# 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 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!

• 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 ? Commented Dec 19, 2016 at 22:46
• The conversion in-code and output is up to you, the Input will be an integer though. @LuisMendo Commented Dec 19, 2016 at 22:51
• 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. Commented Dec 20, 2016 at 9:46

# Whispers v3, 77 69 bytes

> Input
> 0
>> L!
>> … 2 1 3
>> L*L
>> Each 5 4
>> ∑6
>> Output 7


Try it online!

Yet another 69 byte answer thanks to Leo.

• Using … instead of the first Each is shorter: tio.run/##K8/ILC5ILSo2@v/…
– Leo
Commented Feb 8, 2021 at 23:18
• That's new to me as well.. Commented Feb 9, 2021 at 2:51
• The documentation for Whispers v3 is still incomplete, but the tutorial for Whispers v2 has a complete list of "command lines", all still usable
– Leo
Commented Feb 9, 2021 at 2:55

# Pyt, 5 bytes

ř!ṖƩ⁺


Try it online!

ř           implicit input; řangify
!          factorial
Ṗ         raise n to the nth Ṗower
Ʃ        Ʃum
⁺       increment


# Vyxals, 4 bytes

ʀ¡:e


Try it Online!

ʀ  range [0, input]
¡  factorial (vectorizes)
:  duplicate list
e  exponentiate
s  sum


$=>[∑map..0&=>[^<=∏1..&]]  Try it # Stax, 10 bytes Ç╔Ñst(jÖ3l  Run and debug it This is PackedStax, which unpacks to the following 11 bytes: R{|Fc#}m|+^  Run and debug it R{ }m # map over range 1..input |F # push n! c # dup # # exponentiate |+ # sum ^ # increment (deals with 0 case)  # Nibbles, 5.5 bytes +~+.,$^;*,


Attempt This Online!

-0.5 byte thanks to Dominic van Essen

+~+.,$^;*, +~ Add 1 + to the sum . for each n in , range from 1 to$      input
*  of the product of
, range from 1 to
n
^     to the power of
;    itself

• 5.5 bytes... Commented Apr 1, 2023 at 11:43
• @DominicvanEssen I'm dumb… Thanks! Commented Apr 1, 2023 at 21:14
• Correction: 11 bytes -> 5.5 bytes Commented Apr 1, 2023 at 22:09
• Argh… ATO still can't handle the byte counts properly… Commented Apr 2, 2023 at 8:41

# Python 3, 70 bytes

import math
x=lambda n,f=math.factorial:1if n==0else f(n)**f(n)+x(n-1)


Try it online!

• 67 Commented Apr 3, 2023 at 14:06

# C (gcc), 71 70 bytes

-1 byte thanks to @ceilingcat!

i,j,k;a(n){for(j=0;~n;--n,j+=pow(i,i))for(i=k=1;n/++k;)i*=k;return j;}


You can test it online here (Try It Online! seems to lack the pow function).

88 87-byte solution without builtins:

i,j,k,e;a(n){for(j=0;~n;--n,j+=e){for(i=k=1;n/++k;)i*=k;for(e=k=i;--k;)e*=i;}return j;}


Try It Online!

# Thunno 2S, 4 bytes

ĖwD*


Try it online!

#### Explanation

ĖwD*  # Implicit input
Ė     # Push [0..input]
w    # Factorial of each
D*  # To the power of itself
# Implicit output of sum


# Brachylog, 12 bytes

y:{$!F:F^}a+  Try it online! ### Explanation y The list [0, ..., Input] :{ }a Apply the predicate below to each element of that list + The output is the sum of the results$!F              F is the factorial of the input
:F^           Output = F^F


# C#, 79 bytes with console output

n=>{int i=1,j=1;for(;i<=n;i++)j*=i;System.Console.Write(System.Math.Pow(j,j));}


# C#, 64 bytes as a return

n=>{int i=1,j=1;for(;i<=n;i++)j*=i;return System.Math.Pow(j,j);}


# 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


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


# APL (Dyalog), 11 bytes

+/(*⍨∘!0,⍳)


Try it online!

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

# 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

• In 2023, this is 5 bytes òÊ®pZ -x, or if the range was exclusive it would be 4 ÊpUÊ -mx Commented Feb 25, 2023 at 20:43

# Perl 6, 38 bytes

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


Try it online!

• 31 bytes
– Jo King
Commented Apr 22, 2019 at 9:55

# 05AB1E, 8 bytes

ƒN!N!m}O


Try it online!

# Factor + math.factorials math.unicode, 29 bytes

[ [0,b] [ n! dup ^ ] map Σ ]


Try it online!

  [0,b]                      ! range from 0 to input inclusive
[          ] map     ! map over each element in the range
n!                 ! factorial
dup ^           ! raised to itself
Σ   ! sum


# Swift, 129 106 bytes

import Darwin
var s={(0...$0).map{let x=Double($0<1 ?1:(1...\$0).reduce(1,*))
return pow(x,x)}.reduce(0,+)}


Fatal-errors on n < 0, inf for n >= 6. Probably macOS-only due to needing to import Darwin to access the pow(_:_:) function. (Using Darwin instead of Foundation saved both 4 bytes and my sanity.)

When implementing the factorial, I had to hard-code the value for 0 in order to bypass Fatal error: Range requires lowerBound <= upperBound.

There's a space to the left of the ? due to 1 not being optional. We don't need the space to the right.