Raise integer x to power x, without exponentiation built-ins

16

1

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.

user69099

Posted 2017-05-09T22:13:50.030

Reputation:

Can we accept input as a string? – Shaggy – 2017-05-09T22:32:29.770

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 – Mr. Xcoder – 2017-05-10T10:03:22.453

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. – Shaggy – 2017-05-10T10:07:52.620

@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 – Mr. Xcoder – 2017-05-10T10:08:45.687

@Mr.Xcoder, outputting 0 might present more of a challenge in some languages (it'd add 3 bytes to my answer!) but either option works for me. – Shaggy – 2017-05-10T10:12:16.727

>

  • I'm not sure how to interpret "The program must not handle 0". Should that be "need not handle" instead? 2. At present the majority of the answers to this question don't follow the rule that the answer must be a full program. I'm not sure why @Mr.Xcoder added that requirement, but I don't think the question should be reopened until the question is consistent with the existing answers (either because the requirement is removed or because the offending answers have been deleted).
  • < – Peter Taylor – 2017-05-10T10:42:15.067

    @PeterTaylor that's what the OP initially stated, ambiguously though, I will remove that rule. For (1) I will reword that – Mr. Xcoder – 2017-05-10T10:43:43.427

    @PeterTaylor Done, now it's consistent with the answers. – Mr. Xcoder – 2017-05-10T10:44:56.813

    1@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. – Shaggy – 2017-05-10T11:14:25.450

    @Shaggy it's a good edit, now covers everything well – Mr. Xcoder – 2017-05-10T11:16:43.757

    @Shaggy and what was wrong with my good luck wish?)))) – None – 2017-05-12T23:16:08.550

    @Mr. Xcoder for C, i suppose this will be an function int f(x), which will compile in gcc and ms visual studio. so we can put that code in some code.h file. then make our test program like follows: #include <stdio.h> #include "code.h" int main() { int i; for(i=1; i<11;i++) printf("%u %u\n", i, f(i)); return 0; } bytesize of code.h is measured – None – 2017-05-12T23:50:23.850

    Next time: Evaluate the xth hyperoperation of x – Matthew Roh – 2017-05-15T10:00:40.270

    @xakepp35 people (for some reason) on this site dislike wishing people luck. And it was Peter Taylor, not Shaggy who deleted it. – caird coinheringaahing – 2017-07-09T20:37:26.150

    Answers

    15

    APL (Dyalog), 4 bytes

    For xx, takes x as left argument and x as right argument.

    ×/⍴⍨
    

    Try all cases online!

    ×/ product of

    ⍴⍨ arg copies arg

    And here here is one that handles negative integers too:

    ×/|⍴|*×
    

    Try all cases!

    ×/ the product of

    | absolute value

    repetitions of

    | the absolute value

    * to the power of

    × the signum

    The built-in Power primitive is:

    x*y
    

    Adám

    Posted 2017-05-09T22:13:50.030

    Reputation: 37 779

    13

    Python, 25 bytes

    lambda n:eval('1'+'*n'*n)
    

    Try it online!

    xnor

    Posted 2017-05-09T22:13:50.030

    Reputation: 115 687

    9

    Mathematica, 16 bytes

    I've got two solutions at this byte count:

    1##&@@#~Table~#&
    

    Here, #~Table~# creates a list of n copies of n. Then the List head is replaced by 1##& which multiplies all its arguments together.

    Nest[n#&,1,n=#]&
    

    This simply stores the input in n and then multiplies 1 by n, n times.

    Martin Ender

    Posted 2017-05-09T22:13:50.030

    Reputation: 184 808

    1#~Product~{#}& – alephalpha – 2017-05-12T13:14:31.913

    1@alephalpha ah, good point. You can post that as a separate answer. – Martin Ender – 2017-05-12T13:31:22.087

    5

    JavaScript (ES6), 33 28 25 24 bytes

    n=>g=(x=n)=>--x?n*g(x):n
    

    Try It

    f=
    n=>g=(x=n)=>--x?n*g(x):n
    o.innerText=f(i.value=3)()
    i.oninput=_=>o.innerText=f(+i.value)()
    <input id=i min=1 type=number><pre id=o>


    History

    25 bytes

    f=(n,x=n)=>--x?n*f(n,x):n
    

    28 bytes

    n=>eval(1+("*"+n).repeat(n))
    

    33 bytes

    n=>eval(Array(n).fill(n).join`*`)
    

    Shaggy

    Posted 2017-05-09T22:13:50.030

    Reputation: 24 623

    4

    Pure bash, 43

    echo $[$1<2?1:$[$1<2?2:$1]#`printf 1%0$1d`]
    

    Try it online.

    Not sure if this is bending the rules too much - I'm not using any of the listed banned builtins, but I am using base conversion.

    • printf 1%0$1d outputs a 1 followed by n 0s
    • $[b#a] is an arithmetic expansion to treat a as a base b number, which gives the required result. Unfortunately base <2 does not work, so the extra ?: bits handle input n=1.

    Maximum input is 15, because bash uses signed 64-bit integers (up to 231-1).

    Digital Trauma

    Posted 2017-05-09T22:13:50.030

    Reputation: 64 644

    Same problem as I had, this doesn't work for x=1. Nonetheless, very interesting approach. – Maxim Mikhaylov – 2017-05-10T18:25:17.637

    @MaxLawnboy Thanks for pointing that out - that sadly bloated my answer. Perhaps I can figure out another shorter version... – Digital Trauma – 2017-05-10T19:39:59.073

    Cool stuff. Always wished to learn bash, but always been too lazy for it =) – None – 2017-05-12T23:26:41.477

    4

    Alice, 13 bytes

    /o
    \i@/.&.t&*
    

    Try it online!

    Explanation

    /o
    \i@/...
    

    This is a framework for programs that read and write decimal integers and operate entirely in Cardinal mode (so programs for most arithmetic problems).

    .    Duplicate n.
    &.   Make n copies of n.
    t    Decrement the top copy to n-1.
    &*   Multiply the top two values on the stack n-1 times, computing n^n.
    

    Martin Ender

    Posted 2017-05-09T22:13:50.030

    Reputation: 184 808

    4

    Standard ML, 42 bytes

    fn x=>foldl op*1(List.tabulate(x,fn y=>x))
    

    Try it online!

    Explanation:

    fn y => x                 (* An anonymous function that always returns the inputted value *)
    List.tabulate(x, fn y=>x) (* Create a list of size x where each item is x *)
    foldl op* 1               (* Compute the product of the entire list *)    
    

    musicman523

    Posted 2017-05-09T22:13:50.030

    Reputation: 4 472

    1Welcome to PPCG! – Martin Ender – 2017-05-11T19:20:03.887

    Oh that's awesome! Thanks! – musicman523 – 2017-05-13T17:30:10.347

    3

    Jelly, 3 bytes

    ẋ⁸P
    

    Try it online!

    How?

    ẋ⁸P - Main link: x             e.g. 4
     ⁸  - link's left argument, x       4
    ẋ   - repeat left right times       [4,4,4,4]
      P - product                       256
    

    Jonathan Allan

    Posted 2017-05-09T22:13:50.030

    Reputation: 67 804

    Darn, I wanted to do this. :P – HyperNeutrino – 2017-05-09T22:49:48.653

    @Jonathan Allan is it 3 bytes, or 3 wide-characters? let us view source code hex dump, please, to make correct decision on actual code bytesize. ;-) and make the corrections – None – 2017-05-12T23:20:42.183

    1@xakepp35 Jelly uses a SBCS and the bytes link in the header points to it. The program with hexdump F7 88 50 works as intended. – Dennis – 2017-05-12T23:48:33.933

    @Dennis thanks for reply! i could not ever imagine such a language before =) – None – 2017-05-13T00:17:39.703

    3

    R, 22 bytes

    reads x from stdin.

    prod(rep(x<-scan(),x))
    

    generates a list of x copies of x, then computes the product of the elements of that list. When x=0, the rep returns numeric(0), which is a numeric vector of length 0, but the prod of that is 1, so 0^0=1 by this method, which is consistent with R's builtin exponentiation, so that's pretty neat.

    Try it online!

    Giuseppe

    Posted 2017-05-09T22:13:50.030

    Reputation: 21 077

    3

    Cubix, 19 bytes

    ..@OI:1*s;pu!vqW|($
    

    Try it online!

    Step by Step

    Expands out onto a cube with side length 2

        . .
        @ O
    I : 1 * s ; p u
    ! v q W | ( $ .
        . .
        . .
    
    • I:1 Takes the input, duplicates it and pushs 1. This sets up the stack with a counter, multiplier and result.
    • *s; Multiples the TOS, swaps the result with previous and remove previous.
    • pu Bring the counter item to the TOS. U-turn. This use to be a lane change, but needed to shave a byte.
    • |($ This was done to save a byte. When hit it skips the decrement. reflects, decrements the counter and skips the no op wrapping around the cube.
    • !vqW Test the counter. If truthy skip the redirect, put the counter on BOS, change lane back onto the multiplier. Otherwise redirect.
    • |sO@ this is the end sequence redirected to from counter test. Goes past the horizontal reflect, swaps the TOS bringing result to the TOS, ouput and halt.

    MickyT

    Posted 2017-05-09T22:13:50.030

    Reputation: 11 735

    3

    x86_64 machine language for Linux, 14 11 10 bytes

    0:   6a 01                   pushq  $0x1
    2:   58                      pop    %rax
    3:   89 f9                   mov    %edi,%ecx
    5:   f7 ef                   imul   %edi
    7:   e2 fc                   loop   5
    9:   c3                      retq
    

    To Try it online!, compile and run the following C program.

    const char h[]="\x6a\1\x58\x89\xf9\xf7\xef\xe2\xfc\xc3";
    
    int main(){
      for( int i = 1; i < 4; i++ ) {
        printf( "%d %d\n", i, ((int(*)())h)(i) );
      }
    }
    

    ceilingcat

    Posted 2017-05-09T22:13:50.030

    Reputation: 5 503

    2

    Ruby, 20 18 bytes

    -2 bytes because the spec changed and I no longer need an exponent argument.

    ->x{eval [x]*x*?*}
    

    Try it online!

    Value Ink

    Posted 2017-05-09T22:13:50.030

    Reputation: 10 608

    2

    05AB1E, 3 bytes

    .DP
    

    Try it online! or Try all examples

    .D  # pop a,b    push b copies of a 
        # 05AB1E implicitly takes from input if there aren't enough values on the stack
        # For input 5, this gives us the array: [5,5,5,5,5]
      P # Take the product of that array
        # Implicit print
    

    Riley

    Posted 2017-05-09T22:13:50.030

    Reputation: 11 345

    Looks like you enjoyed .D. First time I've seen it used. – Magic Octopus Urn – 2017-05-11T19:36:25.523

    ah, i dont get what is happening here.. seems to be too exotic and no explanation on how that works. =( – None – 2017-05-12T23:28:30.420

    @xakepp35 Does that help? – Riley – 2017-05-12T23:32:40.680

    2

    Haskell, 24 23 21 bytes

    f y=product$y<$[1..y]
    

    Try it online!

    • Saved 1 byte, thanks to Laikoni
    • Saved 2 bytes, thanks to nimi

    sudee

    Posted 2017-05-09T22:13:50.030

    Reputation: 551

    1f y=foldr1(*)$y<$[1..y] is a byte shorter. – Laikoni – 2017-05-11T14:19:52.200

    1product$y<$[1..y] – nimi – 2017-05-16T05:27:39.710

    Not sure how I managed to forget about product, thanks! :D – sudee – 2017-05-16T07:53:32.153

    2

    Stacked, 10 bytes

    {!1[n*]n*}
    

    Try it online!

    Two-argument exponentiation for the same size:

    {%1[x*]y*}
    

    Both are functions. Repeats a function that multiplies 1 by n n times.

    Conor O'Brien

    Posted 2017-05-09T22:13:50.030

    Reputation: 36 228

    2

    Scala, 32 26 bytes

    n=>List.fill(n)(n).product
    

    Try it online! (Added conversion to long in the TIO so it wouldn't overflow on n=10.)

    musicman523

    Posted 2017-05-09T22:13:50.030

    Reputation: 4 472

    2

    x86 machine code (Linux), 18 bytes

    31 c0 ff c0 31 db 39 df 74 07 0f af c7 ff c3 eb f5 c3
    

    It expects a C declaration as follows extern int XpowX(int).

    Disassembled

    XpowX:
      # edi : input register
      # ebx : counter
      # eax : result register
      xor  %eax, %eax    # result  = 0
      inc  %eax          # result += 1
      xor  %ebx, %ebx    # counter = 0
      loop:
        cmp  %ebx, %edi  # if (counter == input)
        je   done        #   return result
        imul %edi, %eax  # result  *= input
        inc        %ebx  # counter += 1
        jmp   loop
      done:
        ret
    

    ბიმო

    Posted 2017-05-09T22:13:50.030

    Reputation: 15 345

    2

    Japt, 4 bytes

    ÆUÃ×
    

    Try it online!

    Explanation

    ÆUÃ×       // implicit: U = input integer
    Uo{U} r*1  // ungolfed
    
    Uo{ }      // create array [0, U) and map each value to...
       U       //   the input value
          r*1  // reduce with multiplication, starting at 1          
               // implicit output of result
    

    Justin Mariner

    Posted 2017-05-09T22:13:50.030

    Reputation: 4 746

    1

    Brachylog, 6 bytes

    g;?j₎×
    

    Try it online!

    Explanation

              Example input: 5
    g         Group: [5]
     ;?       Pair with the Input: [[5], 5]
       j₎     Juxtapose [5] 5 times: [5, 5, 5, 5, 5]
         ×    Multiply
    

    Fatalize

    Posted 2017-05-09T22:13:50.030

    Reputation: 32 976

    1

    CJam, 7 bytes

    ri_a*:*
    

    Try it online!

    Explanation

    ri       e# Read an int from input
      _      e# Duplicate it
       a*    e# Put the copy in the array and repeat it that many times
         :*  e# Take the product of the array
    

    Business Cat

    Posted 2017-05-09T22:13:50.030

    Reputation: 8 927

    1

    dc, 24 23 26 22 bytes

    This is my first attempt writing a recursive macro in dc. I am sure it is a sub-optimal solution which can be improved a lot.

    dsr1+[lrr1-d1<F*]dsFxp
    

    Try it online!

    Edit: Thanks eush77! -4 bytes.

    Maxim Mikhaylov

    Posted 2017-05-09T22:13:50.030

    Reputation: 571

    1Does not work for x=1. – eush77 – 2017-05-10T17:57:58.390

    You can shave off two bytes by replacing lr sequences at the end with two ds at the beginning. – eush77 – 2017-05-10T18:29:17.537

    Actually, you don't need that. Just increment the top of the stack before calling for the first time. This way you will end up with x copies of x on the stack (and 1 of course), and x multiplications thereafter. So the ending can just be plain dsFxp. – eush77 – 2017-05-10T18:35:12.610

    @eush77 I was about to say that removing second lr wouldn't work here. It's my first time golfing in a stack-based language, so it feels very unusual. Thanks for your help! – Maxim Mikhaylov – 2017-05-10T18:46:39.620

    1

    Perl 6, 13 bytes

    {[*] $_ xx$_}
    

    $_ xx $_ evaluates to a list of $_ copies of $_ ($_ being the argument to the anonymous function), and then [*] reduces that list with multiplication.

    Sean

    Posted 2017-05-09T22:13:50.030

    Reputation: 4 136

    1

    CJam, 6 bytes

    ri_m*,
    

    Try it online!

    ri       e# Read integer
      _      e# Duplicate
       m*    e# Cartesian power. The first argument is interpreted as a range
         ,   e# Number of elements. Implicitly display
    

    Luis Mendo

    Posted 2017-05-09T22:13:50.030

    Reputation: 87 464

    1

    Clojure, 22

    #(apply *(repeat % %))
    

    :)

    NikoNyrh

    Posted 2017-05-09T22:13:50.030

    Reputation: 2 361

    1

    Röda, 17 bytes

    {product([_]*_1)}
    

    Try it online!

    It's an anonymous function that takes it's input from the stream.

    Explanation:

    {product([_]*_1)}
    {               } /* An anonymous function */
             [_]      /* An array containing the input value */
                *_1   /* repeated times the input value */
     product(      )  /* Product of all values in the array */
    

    fergusq

    Posted 2017-05-09T22:13:50.030

    Reputation: 4 867

    1

    Batch, 58 bytes

    @set n=1
    @for /l %%i in (1,1,%1)do @set/an*=%1
    @echo %n%
    

    Only works for single-digit inputs due to 32-bit arithmetic.

    Neil

    Posted 2017-05-09T22:13:50.030

    Reputation: 95 035

    1

    brainf*ck, 148 bytes

    ,[->+>+<<]>>[-<<+>>]++++++++[<------<------>>-]<[->>+>>+<<<<]>>[-<<+>>]>>-[-<<<<<[>[>+>+<<-]>>[<<+>>-]<<<-]>>[-<<+>>]>>>]<<<++++++++[-<<++++++>>]<<.
    

    Try it online!

    No built-ins ;)

    How it works

    ,                                       - get ascii input
    [->+>+<<]                               - duplicate input
    >>[-<<+>>]                              - shift inputs left to start
    ++++++++[<------<------>>-]             - convert ascii into input numbers
    <[->>+>>+<<<<]                          - get loop intervals (same as input #)
    >>[-<<+>>]                              - shift input back again
    >>-[-<<<<<[>[>+>+<<-]>>[<<+>>-]<<<-]>>  - iterated addition (multiplication)
    [-<<+>>]>>>                             - Shift output back into input
    ]<<<++++++++[-<<++++++>>]<<.            - convert final output to ascii
    

    In a nutshell, this works by multiplying x (the input) by itself x times. (a.k.a. iterating iterated addition). The net result is x^x.

    I/O

    The program takes a single ASCII input, and processes it as it's ASCII index minus 48. The minus 48 is to normalize inputs of actual numbers (4 becomes 52 -> 52-48 -> 4). To input a number higher than 9, use the next corrosponging ASCII character (: -> 58-48 -> 10). The program ouputs in a similar fashion.

    Test I/O

    INPUT > PROCESSED INPUT >> OUTPUT > TRANSLATED OUTPUT
    1 > 1 >> 1 > 1
    2 > 2 >> 4 > 4
    3 > 3 >> K > 27
    

    Since there are no printable ASCII characters after an input of 3, it can only print numbers in theory. Though, you can check all inputs do in fact work on visualizers such as this.

    Graviton

    Posted 2017-05-09T22:13:50.030

    Reputation: 2 295

    1

    Common Lisp, 59 42 40 bytes

    (lambda(x)(apply'*(fill(make-list x)x)))
    

    Try it online!

    ceilingcat

    Posted 2017-05-09T22:13:50.030

    Reputation: 5 503

    1

    MATLAB/Octave, 23 bytes

    @(n)(prod(n*ones(n,1)))
    

    Batman

    Posted 2017-05-09T22:13:50.030

    Reputation: 111

    1

    Python, 32 bytes

    f=lambda g,z=1:z>g or g*f(g,z+1)
    

    Try it online!

    userNaN

    Posted 2017-05-09T22:13:50.030

    Reputation: 111

    Welcome to PPCG! You don't need to count the f= part, so you can shorten your submission to 30 bytes.

    – Steadybox – 2017-07-09T22:32:13.967

    @Steadybox The f= part does need to be counted, because it's recursive, so it relies upon the function being named f in order to work properly – musicman523 – 2017-07-10T02:06:50.187

    @musicman523 Yes, you are right. – Steadybox – 2017-07-10T02:23:53.290

    0

    PHP, 38 Bytes

    for($p=1;$i++<$argn;)$p*=$argn;echo$p;
    

    Try it online!

    Jörg Hülsermann

    Posted 2017-05-09T22:13:50.030

    Reputation: 13 026

    Drop that ,$i=0. – Christoph – 2017-05-11T12:01:52.917

    @Christoph as I write the answer there was a condition that no error should be throw – Jörg Hülsermann – 2017-05-11T12:06:27.180

    1There's no version of PHP that doesn't ignore E_NOTICE by default. Only with E_NOTICE it is thrown ;) And you really should track your score using <s></s> like everyone else. – Christoph – 2017-05-11T12:11:19.497

    0

    MATL, 5 bytes

    lyX"p
    

    Try it online!

    Explanation

    Example values with input 4.

    l    % Push 1
         % STACK: 1
    y    % Implicit input. Duplicate from below
         % STACK: 4, 1, 4
    X"   % Replicate along two dimensions. Gives a row vector
         % STACK: [4, 4, 4, 4]
    p    % Product of array. Implicitly display.
         % STACK: 256
    

    Luis Mendo

    Posted 2017-05-09T22:13:50.030

    Reputation: 87 464

    0

    QBIC, 12 bytes

    :[a|q=q*a}?q
    

    Explanation:

    :   Get the integer
    [a|     Start a FOR loop, for x iterations
    q=q*a   Multiply q (starts out as 1) by our value, then store that in q
    }       End loop
    ?q      Print q
    

    steenbergh

    Posted 2017-05-09T22:13:50.030

    Reputation: 7 772

    0

    PowerShell, 34 33 bytes

    ,$n,$p=$args,1;1..$n|%{$p*=$n};$p
    

    Try it online!

    Previous version

    ,$n,$ofs=$args,'*';''+@($n)*$n|iex
    

    Andrei Odegov

    Posted 2017-05-09T22:13:50.030

    Reputation: 939

    1Using param($a)'1'+"*$a"*$a|iex works too, more in line with the other String->eval answers, nice to see other PowerShell golfers around, – colsw – 2017-05-11T15:19:04.660

    Your noteworthy code snippet may be transformed to the next one param($a)"$a*"*$a+1|iex. – Andrei Odegov – 2017-05-11T16:48:57.497

    0

    C (gcc), 34 bytes

    i,k;f(x){for(i=k=x;--i;)x*=k;i=x;}
    

    Try it online!

    Steadybox

    Posted 2017-05-09T22:13:50.030

    Reputation: 15 798

    0

    Fourier, 19 bytes

    1~YI~X(Y*X~Yi^~i)Yo
    

    Try it on FourIDE!

    Multiplies Y by the input X number of times and then outputs Y.

    FYI, the standard way to do this would be

    I~XPXo
    

    Where P is the power function

    Beta Decay

    Posted 2017-05-09T22:13:50.030

    Reputation: 21 478

    0

    Retina, 49 46 bytes

    Golfed 3 bytes thanks to @Neil

    .+
    1;$&$*1;$&$*1
    {`1(?=1*;(1+);.)
    $1
    }`1$
    
    \G1
    

    Try it online!

    Supports positive integers just as stated in the challenge.

    user41805

    Posted 2017-05-09T22:13:50.030

    Reputation: 16 320

    I think you can save a byte by using .+ 1;$&$*1;$&$* instead of your first four lines. – Neil – 2017-05-10T19:35:23.443

    And shave three more off by using \G1 instead of your last three lines. – Neil – 2017-05-10T19:38:38.637

    @Neil Ah, \G, that's a neat trick – user41805 – 2017-05-11T09:26:31.590

    0

    Python, 51 bytes

    def f(x,i=0):i=i or x;return x*f(x,i-1)if i>1else x
    

    A little bit more verbose than @xnor's clever way of eval, but uses recursion

    Wondercricket

    Posted 2017-05-09T22:13:50.030

    Reputation: 251

    0

    Groovy, 24 bytes

    {a->r=1;a.times{r*=a};r}
    

    staticmethod

    Posted 2017-05-09T22:13:50.030

    Reputation: 191

    0

    MacOS Bash, 18

    jot -s* -b$1 $1|bc
    

    Try it online.

    Also runs on Linux if you install the jot utility:

    sudo apt install athena-jot
    

    Digital Trauma

    Posted 2017-05-09T22:13:50.030

    Reputation: 64 644

    0

    S.I.L.O.S, 56 bytes

    readIO
    x=i
    readIO
    a=i
    b=1
    lbla
    a-1
    b*x
    if a a
    printInt b
    

    Try it online! Loops through repeated multiplication.

    Rohan Jhunjhunwala

    Posted 2017-05-09T22:13:50.030

    Reputation: 2 569

    0

    Brain-Flak, 76 bytes

    (({})){({}<(({}))>[()])}{}{{}({}<>)({<({}[()])><>({})<>}{}<><{}>)([][()])}{}
    

    Try it online!

    This is an extremely inefficient algorithm, so don't try inputs larger than 7.

    Explanation:

    #Duplicate the input
    (({}))
    
    #Make *n* copies of the input
    {({}<(({}))>[()])}{}
    
    #While the stack has more than one element on it,
    {{}
    
      #Multiply the top two elements
      ({}<>)({<({}[()])><>({})<>}{}<><{}>)
    
      #Push stack-height minus one to keep the loop running
      ([][()])
    
    #Endwhile
    }
    
    #Pop a zero off the main stack, implicitly display the number left on the stack
    {}
    

    James

    Posted 2017-05-09T22:13:50.030

    Reputation: 54 537

    0

    Aceto, 33 bytes

    We have quite a bit of wasted space, so I'm sure we could get rid of a few more bytes.

    =|
    0*v
    ds<
    
     MDL
     &_d
    id!L
    rDM@xp
    

    The bottom half (except for the xp) reads the input, and puts it that many times on the stack, as an integer, i.e. '3' -> [3, 3, 3]. I really need a builtin for that..

    The top half calculates the product by swapping the top two elements, checking if the top element is zero, otherwise multiplying the top two elements, and so on. xp prints.

    L3viathan

    Posted 2017-05-09T22:13:50.030

    Reputation: 3 151

    0

    Pari/GP, 16 bytes

    n->prod(x=1,n,n)
    

    Try it online!

    alephalpha

    Posted 2017-05-09T22:13:50.030

    Reputation: 23 988

    0

    Java 9 JShell, 44 bytes

    x->IntStream.range(0,x).reduce(1,(a,b)->a*x)
    

    Try it online!

    Notes:

    • The imports are not included in the score since they are not required with the default JShell configuration (there are a number of packages imported by the default JShell startup script).
    • Since TIO doesn't have JShell, a Java (OpenJDK 9) program is provided that demonstrates the function, but has been changed to use longs so that 10 to the tenth doesn't overflow, at the expense of one extra byte.

    David Conrad

    Posted 2017-05-09T22:13:50.030

    Reputation: 1 037

    0

    Pyth, 9 bytes

    u*GH*]QQ1
    

    Try it online!

    clap

    Posted 2017-05-09T22:13:50.030

    Reputation: 834

    0

    Pyth, 4

    This took me a while to figure out in pyth, but I finally got there:

    *F*]
    

    Try it online.

    Explanation

       ]Q     # create one-item list (of implicit input)
      *  Q    # repeat (implicit input) times
    *F        # reduce list over multiplication
    

    Digital Trauma

    Posted 2017-05-09T22:13:50.030

    Reputation: 64 644

    0

    tcl, 52

    proc P n {incr p;time {set p [expr $p*$n]} $n;set p}
    

    demo

    sergiol

    Posted 2017-05-09T22:13:50.030

    Reputation: 3 055

    0

    tcl, 50

    proc P n {time {lappend L $n} $n;expr [join $L *]}
    

    demo

    sergiol

    Posted 2017-05-09T22:13:50.030

    Reputation: 3 055

    0

    TI-Basic (TI-84 Plus CE), 9 bytes

    prod(seq(Ans,A,1,Ans
    

    Input is from Ans, output is stored in Ans.

    Run with 5:prgmNAME:Ans (5 or other input) for visual output.

    Generates a list of Ans copies of Ans, then finds the product.

    pizzapants184

    Posted 2017-05-09T22:13:50.030

    Reputation: 3 174

    0

    PowerShell, 36 bytes

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

    Try it online!

    root

    Posted 2017-05-09T22:13:50.030

    Reputation: 241

    0

    Python 2.7, 37 bytes

    Full Program:

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

    Try it online!

    Koishore Roy

    Posted 2017-05-09T22:13:50.030

    Reputation: 1 144

    0

    05AB1E, 2 bytes

    G*
    

    Try it online!

    Explanation

    G*
    G  # Do input - 1 times
     *  # Multiply with input
    

    Datboi

    Posted 2017-05-09T22:13:50.030

    Reputation: 1 213

    0

    Julia 0.6, 18 bytes

    x->prod(x*ones(x))
    

    Tanj

    Posted 2017-05-09T22:13:50.030

    Reputation: 199

    0

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

    Teal pelican

    Posted 2017-05-09T22:13:50.030

    Reputation: 1 338

    0

    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)]
    

    Taylor Scott

    Posted 2017-05-09T22:13:50.030

    Reputation: 6 709

    0

    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!

    Jonah

    Posted 2017-05-09T22:13:50.030

    Reputation: 8 729

    0

    Ly, 16 bytes

    ns<l1-[>l*<1-]>u
    

    Being forced to use multiple stacks costs so many bytes...

    Try it online!

    LyricLy

    Posted 2017-05-09T22:13:50.030

    Reputation: 3 313

    0

    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.

    Titus

    Posted 2017-05-09T22:13:50.030

    Reputation: 13 814

    0

    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
    

    FlipTack

    Posted 2017-05-09T22:13:50.030

    Reputation: 13 242