Given an input, print all exponents where all the bases and powers all up to the input
up vote
5
down vote
favorite
So this is my first challenge on this site.
What this challenge is is that you input a number, and your code spits out numbers which can be calculated as an exponent. The sum of the exponent and base in the number must equal the input.
The numbers must start from $1^{n-1}$ to $(n)^0$.
Example
Given 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$ and so on
Input and Output
Input will be in the form of an integer.
Output will be a list of numbers, delimited by either commas or new lines.
This is code-golf, so shortest code wins.
code-golf math arithmetic
New contributor
add a comment |
up vote
5
down vote
favorite
So this is my first challenge on this site.
What this challenge is is that you input a number, and your code spits out numbers which can be calculated as an exponent. The sum of the exponent and base in the number must equal the input.
The numbers must start from $1^{n-1}$ to $(n)^0$.
Example
Given 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$ and so on
Input and Output
Input will be in the form of an integer.
Output will be a list of numbers, delimited by either commas or new lines.
This is code-golf, so shortest code wins.
code-golf math arithmetic
New contributor
2
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
– Sparr
1 hour ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
1 hour ago
Inputs will always be positive
– Embodiment of Ignorance
45 mins ago
What do I do if there are two answers with the same length, and they both are the shortest?
– Embodiment of Ignorance
36 mins ago
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).
– Οurous
24 mins ago
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
So this is my first challenge on this site.
What this challenge is is that you input a number, and your code spits out numbers which can be calculated as an exponent. The sum of the exponent and base in the number must equal the input.
The numbers must start from $1^{n-1}$ to $(n)^0$.
Example
Given 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$ and so on
Input and Output
Input will be in the form of an integer.
Output will be a list of numbers, delimited by either commas or new lines.
This is code-golf, so shortest code wins.
code-golf math arithmetic
New contributor
So this is my first challenge on this site.
What this challenge is is that you input a number, and your code spits out numbers which can be calculated as an exponent. The sum of the exponent and base in the number must equal the input.
The numbers must start from $1^{n-1}$ to $(n)^0$.
Example
Given 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$ and so on
Input and Output
Input will be in the form of an integer.
Output will be a list of numbers, delimited by either commas or new lines.
This is code-golf, so shortest code wins.
code-golf math arithmetic
code-golf math arithmetic
New contributor
New contributor
edited 45 mins ago
user202729
13.6k12550
13.6k12550
New contributor
asked 1 hour ago
Embodiment of Ignorance
824
824
New contributor
New contributor
2
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
– Sparr
1 hour ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
1 hour ago
Inputs will always be positive
– Embodiment of Ignorance
45 mins ago
What do I do if there are two answers with the same length, and they both are the shortest?
– Embodiment of Ignorance
36 mins ago
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).
– Οurous
24 mins ago
add a comment |
2
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
– Sparr
1 hour ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
1 hour ago
Inputs will always be positive
– Embodiment of Ignorance
45 mins ago
What do I do if there are two answers with the same length, and they both are the shortest?
– Embodiment of Ignorance
36 mins ago
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).
– Οurous
24 mins ago
2
2
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
– Sparr
1 hour ago
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
– Sparr
1 hour ago
3
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
1 hour ago
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
1 hour ago
Inputs will always be positive
– Embodiment of Ignorance
45 mins ago
Inputs will always be positive
– Embodiment of Ignorance
45 mins ago
What do I do if there are two answers with the same length, and they both are the shortest?
– Embodiment of Ignorance
36 mins ago
What do I do if there are two answers with the same length, and they both are the shortest?
– Embodiment of Ignorance
36 mins ago
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).
– Οurous
24 mins ago
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).
– Οurous
24 mins ago
add a comment |
10 Answers
10
active
oldest
votes
up vote
1
down vote
Clean, 37 bytes
import StdEnv
$n=[i^(n-i)\i<-[1..n]]
Try it online!
Defines $ :: Int -> [Int]
taking an integer and returning the list of results.
$ n // function $ of n
= [i ^ (n-i) // i to the power of n minus i
\ i <- [1..n] // for each i in 1 to n
]
add a comment |
up vote
1
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
add a comment |
up vote
1
down vote
Pyth, 5 bytes
_m^-Q
Try it online!
Optimally encoded this would be 4.106 bytes.
_ reverse of the following list:
m map the following lambda d:
^ (N-d)**d
-Qd
d
Q over [0,...,N-1]
add a comment |
up vote
1
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
add a comment |
up vote
1
down vote
Haskell, 23 bytes
f i=[x^(i-x)|x<-[1..i]]
Try it online!
Alternative version, also 23 bytes:
f i=(^)<*>(i-)<$>[1..i]
add a comment |
up vote
0
down vote
JavaScript (Node.js), 36 bytes
f=(n,i=1)=>n--?[i++**n,...f(n,i)]:
Try it online!
JavaScript (Node.js), 37 bytes
n=>[...Array(n)].map(x=>++i**--n,i=0)
Try it online!
add a comment |
up vote
0
down vote
Jelly, 5 bytes
R*ḶU$
Try it online!
R [1,...,n]
* to the power of
ḶU$ [0,...,n-1] reversed
add a comment |
up vote
0
down vote
Perl 6, 19 bytes
{^$_+1 Z**[R,] ^$_}
Try it online!
Anonymous code block that takes a number and returns a list. Zip multiplies the range 1 to input
and the range input-1 to 0
add a comment |
up vote
0
down vote
R, 34 bytes
x=1:scan();cat(x^rev(x-1),sep=',')
Try it online!
add a comment |
up vote
0
down vote
Octave, 21 bytes
@(n)(1:n).^(n-1:-1:0)
Try it online!
add a comment |
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Clean, 37 bytes
import StdEnv
$n=[i^(n-i)\i<-[1..n]]
Try it online!
Defines $ :: Int -> [Int]
taking an integer and returning the list of results.
$ n // function $ of n
= [i ^ (n-i) // i to the power of n minus i
\ i <- [1..n] // for each i in 1 to n
]
add a comment |
up vote
1
down vote
Clean, 37 bytes
import StdEnv
$n=[i^(n-i)\i<-[1..n]]
Try it online!
Defines $ :: Int -> [Int]
taking an integer and returning the list of results.
$ n // function $ of n
= [i ^ (n-i) // i to the power of n minus i
\ i <- [1..n] // for each i in 1 to n
]
add a comment |
up vote
1
down vote
up vote
1
down vote
Clean, 37 bytes
import StdEnv
$n=[i^(n-i)\i<-[1..n]]
Try it online!
Defines $ :: Int -> [Int]
taking an integer and returning the list of results.
$ n // function $ of n
= [i ^ (n-i) // i to the power of n minus i
\ i <- [1..n] // for each i in 1 to n
]
Clean, 37 bytes
import StdEnv
$n=[i^(n-i)\i<-[1..n]]
Try it online!
Defines $ :: Int -> [Int]
taking an integer and returning the list of results.
$ n // function $ of n
= [i ^ (n-i) // i to the power of n minus i
\ i <- [1..n] // for each i in 1 to n
]
edited 1 hour ago
answered 1 hour ago
Οurous
5,86311032
5,86311032
add a comment |
add a comment |
up vote
1
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
add a comment |
up vote
1
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
add a comment |
up vote
1
down vote
up vote
1
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
edited 1 hour ago
answered 1 hour ago
Shieru Asakoto
2,350314
2,350314
add a comment |
add a comment |
up vote
1
down vote
Pyth, 5 bytes
_m^-Q
Try it online!
Optimally encoded this would be 4.106 bytes.
_ reverse of the following list:
m map the following lambda d:
^ (N-d)**d
-Qd
d
Q over [0,...,N-1]
add a comment |
up vote
1
down vote
Pyth, 5 bytes
_m^-Q
Try it online!
Optimally encoded this would be 4.106 bytes.
_ reverse of the following list:
m map the following lambda d:
^ (N-d)**d
-Qd
d
Q over [0,...,N-1]
add a comment |
up vote
1
down vote
up vote
1
down vote
Pyth, 5 bytes
_m^-Q
Try it online!
Optimally encoded this would be 4.106 bytes.
_ reverse of the following list:
m map the following lambda d:
^ (N-d)**d
-Qd
d
Q over [0,...,N-1]
Pyth, 5 bytes
_m^-Q
Try it online!
Optimally encoded this would be 4.106 bytes.
_ reverse of the following list:
m map the following lambda d:
^ (N-d)**d
-Qd
d
Q over [0,...,N-1]
edited 58 mins ago
answered 1 hour ago
lirtosiast
15.5k436105
15.5k436105
add a comment |
add a comment |
up vote
1
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
add a comment |
up vote
1
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
MathGolf, 6 bytes
rx╒m#
Try it online!
answered 46 mins ago
Jo King
19.5k245102
19.5k245102
add a comment |
add a comment |
up vote
1
down vote
Haskell, 23 bytes
f i=[x^(i-x)|x<-[1..i]]
Try it online!
Alternative version, also 23 bytes:
f i=(^)<*>(i-)<$>[1..i]
add a comment |
up vote
1
down vote
Haskell, 23 bytes
f i=[x^(i-x)|x<-[1..i]]
Try it online!
Alternative version, also 23 bytes:
f i=(^)<*>(i-)<$>[1..i]
add a comment |
up vote
1
down vote
up vote
1
down vote
Haskell, 23 bytes
f i=[x^(i-x)|x<-[1..i]]
Try it online!
Alternative version, also 23 bytes:
f i=(^)<*>(i-)<$>[1..i]
Haskell, 23 bytes
f i=[x^(i-x)|x<-[1..i]]
Try it online!
Alternative version, also 23 bytes:
f i=(^)<*>(i-)<$>[1..i]
answered 46 mins ago
nimi
30.9k31985
30.9k31985
add a comment |
add a comment |
up vote
0
down vote
JavaScript (Node.js), 36 bytes
f=(n,i=1)=>n--?[i++**n,...f(n,i)]:
Try it online!
JavaScript (Node.js), 37 bytes
n=>[...Array(n)].map(x=>++i**--n,i=0)
Try it online!
add a comment |
up vote
0
down vote
JavaScript (Node.js), 36 bytes
f=(n,i=1)=>n--?[i++**n,...f(n,i)]:
Try it online!
JavaScript (Node.js), 37 bytes
n=>[...Array(n)].map(x=>++i**--n,i=0)
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
JavaScript (Node.js), 36 bytes
f=(n,i=1)=>n--?[i++**n,...f(n,i)]:
Try it online!
JavaScript (Node.js), 37 bytes
n=>[...Array(n)].map(x=>++i**--n,i=0)
Try it online!
JavaScript (Node.js), 36 bytes
f=(n,i=1)=>n--?[i++**n,...f(n,i)]:
Try it online!
JavaScript (Node.js), 37 bytes
n=>[...Array(n)].map(x=>++i**--n,i=0)
Try it online!
answered 1 hour ago
Shieru Asakoto
2,350314
2,350314
add a comment |
add a comment |
up vote
0
down vote
Jelly, 5 bytes
R*ḶU$
Try it online!
R [1,...,n]
* to the power of
ḶU$ [0,...,n-1] reversed
add a comment |
up vote
0
down vote
Jelly, 5 bytes
R*ḶU$
Try it online!
R [1,...,n]
* to the power of
ḶU$ [0,...,n-1] reversed
add a comment |
up vote
0
down vote
up vote
0
down vote
Jelly, 5 bytes
R*ḶU$
Try it online!
R [1,...,n]
* to the power of
ḶU$ [0,...,n-1] reversed
Jelly, 5 bytes
R*ḶU$
Try it online!
R [1,...,n]
* to the power of
ḶU$ [0,...,n-1] reversed
edited 1 hour ago
answered 1 hour ago
lirtosiast
15.5k436105
15.5k436105
add a comment |
add a comment |
up vote
0
down vote
Perl 6, 19 bytes
{^$_+1 Z**[R,] ^$_}
Try it online!
Anonymous code block that takes a number and returns a list. Zip multiplies the range 1 to input
and the range input-1 to 0
add a comment |
up vote
0
down vote
Perl 6, 19 bytes
{^$_+1 Z**[R,] ^$_}
Try it online!
Anonymous code block that takes a number and returns a list. Zip multiplies the range 1 to input
and the range input-1 to 0
add a comment |
up vote
0
down vote
up vote
0
down vote
Perl 6, 19 bytes
{^$_+1 Z**[R,] ^$_}
Try it online!
Anonymous code block that takes a number and returns a list. Zip multiplies the range 1 to input
and the range input-1 to 0
Perl 6, 19 bytes
{^$_+1 Z**[R,] ^$_}
Try it online!
Anonymous code block that takes a number and returns a list. Zip multiplies the range 1 to input
and the range input-1 to 0
answered 1 hour ago
Jo King
19.5k245102
19.5k245102
add a comment |
add a comment |
up vote
0
down vote
R, 34 bytes
x=1:scan();cat(x^rev(x-1),sep=',')
Try it online!
add a comment |
up vote
0
down vote
R, 34 bytes
x=1:scan();cat(x^rev(x-1),sep=',')
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
R, 34 bytes
x=1:scan();cat(x^rev(x-1),sep=',')
Try it online!
R, 34 bytes
x=1:scan();cat(x^rev(x-1),sep=',')
Try it online!
answered 1 hour ago
Giuseppe
16.1k31052
16.1k31052
add a comment |
add a comment |
up vote
0
down vote
Octave, 21 bytes
@(n)(1:n).^(n-1:-1:0)
Try it online!
add a comment |
up vote
0
down vote
Octave, 21 bytes
@(n)(1:n).^(n-1:-1:0)
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
Octave, 21 bytes
@(n)(1:n).^(n-1:-1:0)
Try it online!
Octave, 21 bytes
@(n)(1:n).^(n-1:-1:0)
Try it online!
answered 13 mins ago
tsh
8,05011346
8,05011346
add a comment |
add a comment |
Embodiment of Ignorance is a new contributor. Be nice, and check out our Code of Conduct.
Embodiment of Ignorance is a new contributor. Be nice, and check out our Code of Conduct.
Embodiment of Ignorance is a new contributor. Be nice, and check out our Code of Conduct.
Embodiment of Ignorance is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176666%2fgiven-an-input-print-all-exponents-where-all-the-bases-and-powers-all-up-to-the%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
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
– Sparr
1 hour ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
1 hour ago
Inputs will always be positive
– Embodiment of Ignorance
45 mins ago
What do I do if there are two answers with the same length, and they both are the shortest?
– Embodiment of Ignorance
36 mins ago
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).
– Οurous
24 mins ago