# 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   4.0310784*10^12
7   3.3197664*10^18
8   5.5696438*10^25


# 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 at 2:40

# 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 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 at 17:15
• Jelly will still be the winner, 3 bytes is damn short Oct 4 at 17:55
• Tied with Gaia now.
Oct 4 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 at 14:00

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

# 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 at 5:36
• @Adám nice, i wasn't aware of this use of commute Oct 8 at 9:19

# 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 at 19:27

# Husk, 5 bytes

Πm´^ḣ


Try it online!

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


# JavaScript (ES7), 20 bytes

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


Try it online!

# R, 20 bytes

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


Try it online!

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


Try it online!

# Kotlin, 59 bytes

fun h(i:Double):Double=if(i<1)1.0 else Math.pow(i,i)*h(i-1)


Try it online!

Longest submission yet, but thought I might as well give Kotlin a shot. Used the = format for functions to eliminate 2 brackets as well as the return.

• Welcome to Code Golf! Nice answer! Oct 4 at 18:46

# Java (JDK), 51 bytes

n->{var r=1;for(;n>0;)r*=Math.pow(n,n--);return r;}


Try it online!

# Factor + math.unicode, 33 27 bytes

[ [1,b] [ dup ^n ] map Π ]


Try it online!

This could have been 26 bytes, but ^ returns NaN for 0^0. Factor is the only language I know of that doesn't just return 1 for that. So I had to use ^n instead, which is a helper word used to implement ^ that hasn't been 'fixed' yet.

• [1,b] A range from 1 to whatever is on top of the data stack, inclusive.
• dup ^n Raise an integer to itself.
• [ ... ] map Apply a quotation to each element of a sequence, collecting the results in a new sequence of the same length.
• Π Product of a sequence.
• You can add Mathematica to that list :)
– att
Oct 5 at 19:59

# Python 3, 28 bytes

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


Try it online!

# C (gcc), 28 bytes

H(n){n=n?pow(n,n)*H(--n):1;}


Try it online!

# 05AB1E, 4 bytes

LDmP


Explanation:

L     # Push a list in the range [1, (implicit) input-integer]
# (note: input 0 will create the list [1,0])
D    # Duplicate this list
m   # Take the exponent of the two lists at the same positions
P  # Take the product of this list
# (after which the result is output implicitly)


# Wren, 43 bytes

var F=Fn.new{|n|n<1?1:n.pow(n)*F.call(n-1)}


Try it online!

Alternate:

# Wren, 44 bytes

Fn.new{|n|(1..n).reduce(1){|a,b|a*b.pow(b)}}


Try it online!

• wow reminds me a lot of rust Oct 5 at 4:33

<<<$a Attempt This 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.

# TI-BASIC, 13 bytes

(TI-84+ only, for randIntNoRep()

max(1,randIntNoRep(1,Ans
prod(Ans^Ans


Takes input as the last expression entered, like so:

0:prgmH
1
2:prgmH
4
4:prgmH
27648
5:prgmH
86400000


NB: TI-BASIC is a tokenized language; that means the textual representation of bytes can be multiple characters. In fact, e.g., randIntNoRep( is a single character that cannot be edited as one might edit an ASCII string. This program is represented by the following hex bytes (if I translated it right):

19 31 2B EF 35 31 2B 72 3F B7 72 F0 72


Based off of this site. All tokens are one byte, with the exception of randIntNoRep(, which is represented with two bytes, EF 35. 3F represents the newline.

## Explanation

randIntNoRep(1,Ans returns a range of numbers from 1 to Ans. This is, as far as I can tell, the shortest way to generate a range. This occupies 5 bytes. For Ans = 0, we get either {0, 1} or {1, 0} depending on the RNG. Since TI-BASIC errors out when trying to compute $$\0^0\$$, we need to remove the zeroes by taking the max of each element with 1 (max(1,. Even though we compute 1^1 twice for Ans = 0, this does not affect the overall product.

Next, we simply compute the hyperfactorial factors as Ans^Ans, raising the list to the power of itself. After, we take the prod( of this list, returning a single number.

# TI-Basic, 19 17 14 bytes

prod(seq(I^I,I,1,Ans+not(Ans


sadly 0^0 or an empty list errors, so 0 has to be turned into 1

# Charcoal, 8 bytes

ＩΠＥ⊕ＮＸιι


Try it online! Link is to verbose version of code. Explanation:

    Ｎ       Input n as a number
⊕        Incremented
Ｅ         Map over implicit range
ι     Current value
Ｘ      Raised to power
ι    Current value
Π          Product
Ｉ           Cast to string
Implicitly print


# CJam, 11 bytes

1ri,{)_#*}%


Try it online!

### How it works

1             e# Push 1
ri           e# Read input and intepret as an integer, n
,          e# Range. Gives [0 1 2 -... n-1]
{    }%   e# For each k in the range
_       e# Duplicate
#      e# Power
*     e# Product
e# Implicit display

• Also ri),_]ze~:* Oct 4 at 10:50

# Ruby, 24 bytes

f=->n{n<1?1:n**n*f[n-1]}


Try it online!

• You are right, sorry.
– G B
Oct 4 at 12:36

# Japt, 6 bytes

õ_pZÃ×


Try it here

# PowerShell, 51 bytes

param($n)iex((1..$n|%{[math]::pow($_,$_)})-join'*')


Try it online!

It is rare to see Powershell answers without spaces

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

# Scala, 43 bytes

1.to(_)./:(1)((a,n)=>a*math.pow(n,n).toInt)


Try it in Scastie!

For comparison, the recursive solution is 56 bytes:

def f(n:Int):Int=if(n>0)math.pow(n,n).toInt*f(n-1)else 1


# Pip, 9 bytes

Y\,a$*yEy  Takes input via command-line argument. Try it here! Or, here's a 10-byte equivalent in Pip Classic: Try it online! ### Explanation  \,a Inclusive range from 1 to command-line arg Y Yank that into y yEy y to the power of y$*     Fold on multiplication