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 ¦
+----------------------------------------------------------------------------------------------------+
5the 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 – Sparr – 2018-11-28T04:20:16.577
3Is the input always greater than 0 or do we have to deal with 0 and negatives? – Veskah – 2018-11-28T04:21:00.550
Inputs will always be positive – Embodiment of Ignorance – 2018-11-28T05:01:12.800
6Two 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). – Οurous – 2018-11-28T05:21:58.843
Are we allowed to start with 0^n or must we start at 1? – JDL – 2018-11-28T10:58:52.207
2Shouldn't the title be "Given an integer, print all the powers obtained with a base and an exponent that sum to the input"? – Nicola Sap – 2018-11-28T14:12:35.363
is a trailing comma at the end of the output allowed? – bznein – 2018-11-29T13:09:28.547
You can have a trailing comma, since it doesn't interfere with the primary objective – Embodiment of Ignorance – 2018-11-29T16:19:41.383
@NicolaSap Should probably also be a positive integer. – None – 2018-11-30T08:06:43.847