# Given an input, print all exponents where the base and power sum to the input

So this is my first challenge on this site.

The challenge is to take in an input integer $$\n\$$, which will be positive, and print, in ascending order ($$\1\$$ to $$\n\$$, including n), the output of $$\i^{(n-i)}\$$ (where $$\i\$$ is the current integer).

# Example

Given the input 5, the program will print:

1
8
9
4
1


$$\1^4\$$ is 1 and $$\1+4=5\$$
$$\2^3\$$ is 8 and $$\2+3=5\$$
$$\3^2\$$ is 9 and $$\3+2=5\$$
$$\4^1\$$ is 4 and $$\4+1=5\$$
$$\5^0\$$ is 1 and $$\5+0=5\$$

# Input and Output

Input will be in the form of a positive integer. Output will be a list of numbers, delimited by either commas or new lines.

This is , so shortest code wins.

• the comma/newline detail should be omitted, it is normal practice around here to let output of lists be in any convenient format, including as a list/array object being returned by a function Commented Nov 28, 2018 at 4:20
• Is the input always greater than 0 or do we have to deal with 0 and negatives? Commented Nov 28, 2018 at 4:21
• Inputs will always be positive Commented Nov 28, 2018 at 5:01
• Two equally short answers doesn't matter. If you feel like accepting an answer, choose the earliest posted one. However I strongly recommend waiting at least a few days, and would suggest never accepting an answer (to encourage more submissions). Commented Nov 28, 2018 at 5:21
• Shouldn't the title be "Given an integer, print all the powers obtained with a base and an exponent that sum to the input"? Commented Nov 28, 2018 at 14:12

# C++ (clang), 80 bytes, 71 bytes, 63 bytes, 59 bytes, 56 bytes

int n,c=1;cin>>n;for(;c<=n;++c){cout<<pow(c,n-c)<<endl;}


Try it online!

# Pari/GP, 22 bytes

n->[i^(n-i)|i<-[1..n]]


Try it online!

# PowerShell, 39 bytes

param($n)1..$n|%{"1"+"*$_"*($n-$_)|iex}  Try it online! Because exponents are expensive in Powershell, this works by using invoke-expression to parse and calculate the string "1*n*n...*n" Works because the first and last entry are always 1. • Nice. The length of param($n)1..$n|%{[Math]::Pow($_,$n-$_)} is 39 bytes too :) Commented Dec 7, 2018 at 9:10
• @mazzy I actually did check that after posting this and chuckled at finding out. Commented Dec 7, 2018 at 20:59

# Gambit Scheme (gsi), 52 bytes

(lambda(x)(map(lambda(y)(expt y(-x y)))(iota x 1)))


For some reason this code does not appear to work on TIO. It works fine on my machine.

Explanation:

(lambda(x)(map(lambda(y)(expt y(- x y)))(iota x 1)))    Full program
(lambda(x)                                        )    Anonymous function with arg x
(map(lambda(y)              )(iota x 1))     Map over the range 1 to input
(expt y                        Raises the mapped value to...
(- x y)                 The input value minus the mapped value (this powers the list by the reverse)


# Thunno 2, 5 bytes

RD$_*  Try it online! #### Explanation RD$_*  # Implicit input
R      # Push [1..input]
D     # Duplicate
$_ # Subtract from input * # Exponentiate # Implicit output  # C (gcc) (-lm), 52 bytes f(n,i){for(i=n;i--;printf("%.0f\n",pow(n-i,i)));}  Try it online! • Can't you just use %.f withouth the 0? Also, in a trailing comma is allowed, youcan replace \n with , Commented Nov 29, 2018 at 13:11 # APL(NARS), 11 chars, 22 bytes {⍪⍵*⌽⍵-1}∘⍳  test:  f←{⍪⍵*⌽⍵-1}∘⍳ f 5 1 8 9 4 1  SAS, 71 bytes data a;input n;o=cat(1);do x=1 to n-1;o=catx(',',(n-x)**x,o);end;cards;  Input goes after the cards; statement, separated by newlines, like so: data a;input n;o=cat(1);do x=1 to n-1;o=catx(',',(n-x)**x,o);end;cards; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Outputs a dataset containing the input n, and comma-separated output string o (and also helper variable x) +----+------------------------------------------------------------------------------------------+----+ | n | o | x | +----+------------------------------------------------------------------------------------------+----+ ¦ 1 ¦ 1 ¦ 1 ¦ ¦ 2 ¦ 1,1 ¦ 2 ¦ ¦ 3 ¦ 1,2,1 ¦ 3 ¦ ¦ 4 ¦ 1,4,3,1 ¦ 4 ¦ ¦ 5 ¦ 1,8,9,4,1 ¦ 5 ¦ ¦ 6 ¦ 1,16,27,16,5,1 ¦ 6 ¦ ¦ 7 ¦ 1,32,81,64,25,6,1 ¦ 7 ¦ ¦ 8 ¦ 1,64,243,256,125,36,7,1 ¦ 8 ¦ ¦ 9 ¦ 1,128,729,1024,625,216,49,8,1 ¦ 9 ¦ ¦ 10 ¦ 1,256,2187,4096,3125,1296,343,64,9,1 ¦ 10 ¦ ¦ 11 ¦ 1,512,6561,16384,15625,7776,2401,512,81,10,1 ¦ 11 ¦ ¦ 12 ¦ 1,1024,19683,65536,78125,46656,16807,4096,729,100,11,1 ¦ 12 ¦ ¦ 13 ¦ 1,2048,59049,262144,390625,279936,117649,32768,6561,1000,121,12,1 ¦ 13 ¦ ¦ 14 ¦ 1,4096,177147,1048576,1953125,1679616,823543,262144,59049,10000,1331,144,13,1 ¦ 14 ¦ ¦ 15 ¦ 1,8192,531441,4194304,9765625,10077696,5764801,2097152,531441,100000,14641,1728,169,14,1 ¦ 15 ¦ +----------------------------------------------------------------------------------------------------+  # C (clang), 47 bytes i;f(a){for(i=a;i;printf("%.f,",pow(i,a-i--)));}  Try it online! Prints in reverse order, delimited with commas. # Arturo, 20 bytes $->n[map n'i->i^n-i]


Try it!