Given an input, print all exponents where all the bases and powers all up to the input
up vote
4
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
4
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
44 mins ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
43 mins ago
Inputs will always be positive
– Embodiment of Ignorance
3 mins ago
add a comment |
up vote
4
down vote
favorite
up vote
4
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 3 mins ago
user202729
13.6k12550
13.6k12550
New contributor
asked 1 hour ago
Embodiment of Ignorance
774
774
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
44 mins ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
43 mins ago
Inputs will always be positive
– Embodiment of Ignorance
3 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
44 mins ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
43 mins ago
Inputs will always be positive
– Embodiment of Ignorance
3 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
44 mins 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
44 mins ago
3
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
43 mins ago
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
43 mins ago
Inputs will always be positive
– Embodiment of Ignorance
3 mins ago
Inputs will always be positive
– Embodiment of Ignorance
3 mins ago
add a comment |
9 Answers
9
active
oldest
votes
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
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
0
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
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
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
0
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
add a comment |
up vote
0
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 |
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 49 mins ago
Shieru Asakoto
2,340314
2,340314
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 42 mins ago
answered 47 mins ago
lirtosiast
15.5k436105
15.5k436105
add a comment |
add a comment |
up vote
0
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
0
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
0
down vote
up vote
0
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 38 mins ago
answered 52 mins ago
Οurous
5,84311032
5,84311032
add a comment |
add a comment |
up vote
0
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
add a comment |
up vote
0
down vote
Wolfram Language (Mathematica), 24 20 18 bytes
(x=Range@#)^(#-x)&
Try it online!
-4 thanks @lirtosiast.
add a comment |
up vote
0
down vote
up vote
0
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 30 mins ago
answered 33 mins ago
Shieru Asakoto
2,340314
2,340314
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 30 mins 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 22 mins ago
Giuseppe
16.1k31052
16.1k31052
add a comment |
add a comment |
up vote
0
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
0
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
0
down vote
up vote
0
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 16 mins ago
answered 21 mins ago
lirtosiast
15.5k436105
15.5k436105
add a comment |
add a comment |
up vote
0
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
add a comment |
up vote
0
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
MathGolf, 6 bytes
rx╒m#
Try it online!
MathGolf, 6 bytes
rx╒m#
Try it online!
answered 4 mins ago
Jo King
19.5k245102
19.5k245102
add a comment |
add a comment |
up vote
0
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
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
up vote
0
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 4 mins ago
nimi
30.9k31985
30.9k31985
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
44 mins ago
3
Is the input always greater than 0 or do we have to deal with 0 and negatives?
– Veskah
43 mins ago
Inputs will always be positive
– Embodiment of Ignorance
3 mins ago