20
\$\begingroup\$

Task - The title pretty much sums it up: raise an integer x to power x, where 0<x.

Restrictions:

  • Use of exponentiation, exp(), ln(), and any other powers-related language built-ins, like pow(), x^x, x**x is forbidden.
  • You can assume that the given integer fits the limits of the programming language of your choice.

Test cases:

Input | Output
---------------
2     | 4
3     | 27
5     | 3125
6     | 46656
10    | 10000000000

This is , so the shortest program in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ Can we accept input as a string? \$\endgroup\$ – Shaggy May 9 '17 at 22:32
  • \$\begingroup\$ I have made an edit to this, hoping it will be reopened. I deleted rule 3 and instead stated that it should be a full program, as the OP probably intended \$\endgroup\$ – Mr. Xcoder May 10 '17 at 10:03
  • \$\begingroup\$ Much better, @Mr.Xcoder but I suggest removing (or rewording) the second restriction. Does "not a function" exclude JS from participating? I'd also suggest, for the purposes of the challenge, that we should have to handle 0 and that the expected output be specified (0 or 1 or either). Finally, having to handle negative integers would be a nice addition to the challenge. \$\endgroup\$ – Shaggy May 10 '17 at 10:07
  • \$\begingroup\$ @Shaggy added js back in... calculated 0^0 on the apple calculator and it returned 1. Maybe 1 should be the chosen value, because Python also returns 1 for 0^0. However, Foundation+ Swift returns 0 \$\endgroup\$ – Mr. Xcoder May 10 '17 at 10:08
  • 1
    \$\begingroup\$ @Mr.Xcoder, I've removed the "restriction" that we need not handle 0 and instead specified that 0<x in the lead-in. I also removed the restriction that code shouldn't throw errors; that should go without saying. Feel free to roll back if necessary. \$\endgroup\$ – Shaggy May 10 '17 at 11:14

72 Answers 72

1 2
3
0
\$\begingroup\$

PowerShell, 36 bytes

$a="$args";$b=1;1..$a|%{$b=$b*$a};$b

Try it online!

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

Python 2.7, 37 bytes

Full Program:

s,x=1,input();exec('s*=x;')*x;print s

Try it online!

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

05AB1E, 2 bytes

G*

Try it online!

Explanation

G*
G  # Do input - 1 times
 *  # Multiply with input
\$\endgroup\$
0
\$\begingroup\$

Julia 0.6, 18 bytes

x->prod(x*ones(x))
\$\endgroup\$
0
\$\begingroup\$

><>, 18 + 3 (-v flag) bytes

:l(?v:
=?v*>l1
n;>

Try it online!

-v flag to put our number on the stack allows for bigger numbers with little over head.

Explination

:l(?v:

:l(     | Copies the stack top, adds the length of the stack then compares.
   ?v:  | Checks if the compare was true,
        |  if not then copy the stack top and loop, else move down.

=?v*>l1 

    >l1 | Move the direction right, add the length of the stack, add 1 to the stack.
=?v*    | Compare the length of the stack to 1,
        |  if the stack is 1 item move down, else multiply the top 2 stack items.

n;>

n;>     | Moves the directions right, then prints the top stack item as a number then ends the program.
\$\endgroup\$
0
\$\begingroup\$

Excel VBA, 34 Bytes

Anonymous VBE immediate window function that takes input from Range [A1] and outputs [A1^A1] to the VBE immediate window

n=1:For i=1To[A1]:n=n*[A1]:Next:?n

Interesting Version, 40 Bytes

Anonymous VBE immediate window function that takes input from Range [A1] and outputs [A1^A1] by method of worksheet manipulation to the VBE immediate window

[A1].Resize([A1],1)=[A1]:?[PRODUCT(A:A)]
\$\endgroup\$
0
\$\begingroup\$

J, 5 bytes

*/@$~
  • $~ shapes the argument into a list with as many items as it is, eg, 3 becomes 3 3 3.
  • @ pipes the result into...
  • */ reduce by multiplication

Try it online!

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

PHP, 44 bytes

<?=array_product(array_fill(1,$argn,$argn));

not the shortest solution; but it might trigger ideas for other languages.

Run as pipe with -R or try it online.

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

Pushy, 5 bytes

&tCP#

Try it online!

         \ Implicit: Input on stack                       [3]
&tC      \ Push (input - 1) extra copies of input         [3, 3, 3]
   P     \ Calculate product                              [3, 3, 3, 27]
    #    \ Output result                                  PRINT 27
\$\endgroup\$
0
\$\begingroup\$

Perl 5 + -p, 17 bytes

$_=eval"$_*"x$_.1

Try it online!

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

Rockstar, 71 62 bytes

listen to N
X's0
P's1
while N-X
let X be+1
let P be*N-0

say P

Try it here (Code will need to be pasted in)

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

Keg, 9 bytes

¿(:;|:)∑*

Try it online!

I said I'd count Keg's victories over 1+ as victories for mawp, so it's 2-1 to mawp!

\$\endgroup\$
  • \$\begingroup\$ No way! (15chrs) \$\endgroup\$ – null Aug 14 '20 at 1:30
  • \$\begingroup\$ @HighlyRadioactive stop vandalising my answer. \$\endgroup\$ – Lyxal Aug 14 '20 at 1:45
  • \$\begingroup\$ stop 2-1ing. (15) \$\endgroup\$ – null Aug 14 '20 at 1:45
  • \$\begingroup\$ Who's post is this? Huh, looks like it's mine. Leave it alone \$\endgroup\$ – Lyxal Aug 14 '20 at 1:46
  • \$\begingroup\$ @HighlyRadioactive I flagged you for vandalizing a single post 10 times in a row. Stop it, or your account will get suspended. \$\endgroup\$ – Bubbler Aug 14 '20 at 2:01
1 2
3

Your Answer

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