# The objective

Given the non-negative integer $$\n\$$, output the value of the hyperfactorial $$\H(n)\$$. You don't have to worry about outputs exceeding your language's integer limit.

# Background

The hyperfactorial is a variant of the factorial function. is defined as $$H(n) = 1^{1} \cdot 2^{2} \cdot 3^{3} \cdot \: \cdots \: \cdot n^{n}$$

For example, $$\H(4) = 1^{1} \cdot 2^{2} \cdot 3^{3} \cdot 4^{4} = 27648\$$.

# Test cases

n   H(n)
0   1
1   1
2   4
3   108
4   27648
5   86400000
6   4031078400000
7   3319766398771200000
8   55696437941726556979200000


# Rules

• I think one might be able to write a competitive 4 bit assembler (or even 8 bit assembler) answer which is a tiny LUT. Oct 5, 2021 at 2:40
• oeis.org/A002109 Nov 14, 2022 at 19:32

# Jelly, 3 bytes

*)P


Try it online!

## How it works

*)P - Main link. Takes n on the left
)  - Over each integer 1 ≤ i ≤ n:
*   -   Raise i to the power i
P - Product

• I will accept this answer since it appears to be the shortest. Oct 4, 2021 at 15:52
• @Nirvana I appreciate that. However, 8 hours is far too short to accept a winner, as it often indicates (unofficially) that the challenge is over. If I accept a winner, I usually wait a minimum of 3 days so that everyone has time to see the challenge. Additionally, we discourage accepting an answer on pure [code-golf] challenges, as we consider these challenges to be competitions within languages (e.g. Jelly vs Jelly, rather than Jelly vs Java), and accepting an answer contradicts that. It's entirely up to you if you'd like to follow that convention however. Oct 4, 2021 at 17:15
• Jelly will still be the winner, 3 bytes is damn short Oct 4, 2021 at 17:55
• Tied with Gaia now.
Oct 4, 2021 at 20:38
• @cairdcoinheringaahing see, and THAT is why we have the occasional "ban golflangs" thread on meta - you can say how things should be and stuff but this is reality Oct 6, 2021 at 14:00

# Wolfram Language (Mathematica), 19 bytes

Product[n^n,{n,#}]&


Try it online!

also as @att mentioned there is a built-in for this...

# Wolfram Language (Mathematica), 14 bytes

Hyperfactorial


Try it online!

• The built-in Hyperfactorial is 14 bytes
– att
Oct 4, 2021 at 19:27

# APL (Dyalog Classic), 5 bytes

⍳×.*⍳


Try it online!

First it evaluates range of the input, and dots the power and takes the product.

• While not as nice looking, ×.*⍨⍳ would be more efficient.
Oct 5, 2021 at 5:36
• @Adám nice, i wasn't aware of this use of commute Oct 8, 2021 at 9:19

# Gaia, 3 bytes

*†Π


Try it online!

† vectorizes the operator on its left, integer arguments are implicitly cast to ranges. * is exponentiation and Π the product of a list.

# JavaScript (ES7), 20 bytes

f=n=>n?n**n*f(n-1):1


Try it online!

# Python 3, 28 bytes

f=lambda n:n<1or n**n*f(n-1)


Try it online!

# Nibbles, 2 bytes

$*@^  Note that this problem influenced how nibbles decides to use implicit args from implicit ops. I'm currently thinking of getting rid of implicit fold since it is uncommonly used though.  # implicit fold since accumulator is used # implicit range from 1 since there's things after an integer$    # first input integer
*   # mult
@  # accumulator from fold
^ # exponentiation
# implicit $since need another arg to ^ # implicit$ since need another arg to ^


# tinylisp, 51 bytes

(load library
(d H(q((N)(i N(*(pow N N)(H(dec N)))1


Try it online!

## Ungolfed

(load library)            ; for *, pow, and dec

(def hyper                ; name something
(lambda (n)             ; a lambda function that takes one parameter n
(if n                 ; if n...
(*                  ; ...is non-zero, multiply...
(pow n n)         ; ...n raised to itself...
(hyper (dec n)))  ; by the hyperfactorial of n-1
1)))                ; otherwise if n is zero, return 1

• 50 bytes non-recursive solution Feb 3, 2022 at 13:22

# Husk, 5 bytes

Πm´^ḣ


Try it online!

Π       # product of
m      # mapping across all values of
ḣ  # 1..input
´^    # x to the power of x


# R, 20 bytes

prod((x=1:scan())^x)


Try it online!

# Haskell, 20 bytes

h 0=1
h n=n^n*h(n-1)


Try it online!

<<<$a Attempt This Online! # Python 3.8 (pre-release), 59 bytes from math import* lambda n:prod(i**i for i in range(1,n+1))  Try it online! # Raku, 17 bytes {[*] [\R*] 1..$_}


Try it online!

• 1 .. $_ is the sequence of numbers from 1 to the input argument. • [\R*] is the "triangular reduction" (scan) of those numbers with the Reversed (and thus right-associative) multiplication operator, producing this list: 𝑛, 𝑛 × (𝑛-1), 𝑛 × (𝑛-1) × (𝑛-2), ..., 𝑛 × (𝑛-1) × (𝑛-2) × ... × 1. • [*] is the product of those numbers, which contains 𝑛 factors of 𝑛, 𝑛-1 factors of 𝑛-1, etc, as required. If the input argument is zero, 1 ..$_ is an empty range, [\R*] applied to that range produces an empty list, and [*] applied to that list returns the multiplicative identity element 1.