27
\$\begingroup\$

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\$
3
  • 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, 2016 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, 2016 at 22:51
  • 4
    \$\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, 2016 at 9:46

49 Answers 49

1
2
1
\$\begingroup\$

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.

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

Pyt, 5 bytes

ř!ṖƩ⁺

Try it online!

ř           implicit input; řangify
 !          factorial
  Ṗ         raise n to the nth Ṗower
   Ʃ        Ʃum
    ⁺       increment
\$\endgroup\$
1
\$\begingroup\$

Vyxal s, 4 bytes

ʀ¡:e

Try it Online!

ʀ  range [0, input]
¡  factorial (vectorizes)
:  duplicate list
e  exponentiate
s  sum
\$\endgroup\$
1
\$\begingroup\$

Arturo, 29 bytes

$=>[∑map..0&=>[^<=∏1..&]]

Try it

\$\endgroup\$
1
\$\begingroup\$

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)
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ 5.5 bytes... \$\endgroup\$ Apr 1 at 11:43
  • \$\begingroup\$ @DominicvanEssen I'm dumb… Thanks! \$\endgroup\$
    – xigoi
    Apr 1 at 21:14
  • \$\begingroup\$ Correction: 11 bytes -> 5.5 bytes \$\endgroup\$ Apr 1 at 22:09
  • \$\begingroup\$ Argh… ATO still can't handle the byte counts properly… \$\endgroup\$
    – xigoi
    Apr 2 at 8:41
1
\$\begingroup\$

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 67 \$\endgroup\$
    – The Thonnu
    Apr 3 at 14:06
1
\$\begingroup\$

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!

\$\endgroup\$
0
1
\$\begingroup\$

Thunno 2 S, 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
\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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);}
\$\endgroup\$
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
\$\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
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog), 11 bytes

+/(*⍨∘!0,⍳)

Try it online!


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

\$\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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ In 2023, this is 5 bytes òÊ®pZ -x, or if the range was exclusive it would be 4 ÊpUÊ -mx \$\endgroup\$
    – noodle man
    Feb 25 at 20:43
0
\$\begingroup\$

Perl 6, 38 bytes

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

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 31 bytes \$\endgroup\$
    – Jo King
    Apr 22, 2019 at 9:55
0
\$\begingroup\$

05AB1E, 8 bytes

ƒN!N!m}O

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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