Smallest Diversifying Exponent
up vote
4
down vote
favorite
A pandigital number is one which contains every digit from 0 to 9 at least once. 1234567890, 1902837465000000, and 9023289761326634265 are all pandigital.
A diverse pair of numbers is a pair of numbers $(a, b)$ such that $a^b$ is pandigital. $b$ is called the diversifying exponent.
Challenge: Given a number $a$, find the smallest corresponding diversifying exponent $b$. This is a code-golf, so the shortest program in bytes wins.
(You may assume that there exists such an exponent, that is, your program will not be given invalid input, such as a power of 10.)
Your solution must be able to handle at the minimum the given test cases, but it should theoretically handle all valid inputs.
This is A090493 on OEIS.
Test cases
2 -> 68
3 -> 39
4 -> 34
5 -> 19
6 -> 20
7 -> 18
8 -> 28
9 -> 24
11 -> 23
12 -> 22
13 -> 22
14 -> 21
15 -> 12
16 -> 17
17 -> 14
18 -> 21
19 -> 17
20 -> 51
21 -> 17
22 -> 18
23 -> 14
24 -> 19
25 -> 11
26 -> 18
27 -> 13
28 -> 11
29 -> 12
30 -> 39
31 -> 11
32 -> 14
33 -> 16
34 -> 14
35 -> 19
36 -> 10
code-golf math
add a comment |
up vote
4
down vote
favorite
A pandigital number is one which contains every digit from 0 to 9 at least once. 1234567890, 1902837465000000, and 9023289761326634265 are all pandigital.
A diverse pair of numbers is a pair of numbers $(a, b)$ such that $a^b$ is pandigital. $b$ is called the diversifying exponent.
Challenge: Given a number $a$, find the smallest corresponding diversifying exponent $b$. This is a code-golf, so the shortest program in bytes wins.
(You may assume that there exists such an exponent, that is, your program will not be given invalid input, such as a power of 10.)
Your solution must be able to handle at the minimum the given test cases, but it should theoretically handle all valid inputs.
This is A090493 on OEIS.
Test cases
2 -> 68
3 -> 39
4 -> 34
5 -> 19
6 -> 20
7 -> 18
8 -> 28
9 -> 24
11 -> 23
12 -> 22
13 -> 22
14 -> 21
15 -> 12
16 -> 17
17 -> 14
18 -> 21
19 -> 17
20 -> 51
21 -> 17
22 -> 18
23 -> 14
24 -> 19
25 -> 11
26 -> 18
27 -> 13
28 -> 11
29 -> 12
30 -> 39
31 -> 11
32 -> 14
33 -> 16
34 -> 14
35 -> 19
36 -> 10
code-golf math
1
I want to point out a special case1234567890 -> 1
.
– Bubbler
2 hours ago
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
A pandigital number is one which contains every digit from 0 to 9 at least once. 1234567890, 1902837465000000, and 9023289761326634265 are all pandigital.
A diverse pair of numbers is a pair of numbers $(a, b)$ such that $a^b$ is pandigital. $b$ is called the diversifying exponent.
Challenge: Given a number $a$, find the smallest corresponding diversifying exponent $b$. This is a code-golf, so the shortest program in bytes wins.
(You may assume that there exists such an exponent, that is, your program will not be given invalid input, such as a power of 10.)
Your solution must be able to handle at the minimum the given test cases, but it should theoretically handle all valid inputs.
This is A090493 on OEIS.
Test cases
2 -> 68
3 -> 39
4 -> 34
5 -> 19
6 -> 20
7 -> 18
8 -> 28
9 -> 24
11 -> 23
12 -> 22
13 -> 22
14 -> 21
15 -> 12
16 -> 17
17 -> 14
18 -> 21
19 -> 17
20 -> 51
21 -> 17
22 -> 18
23 -> 14
24 -> 19
25 -> 11
26 -> 18
27 -> 13
28 -> 11
29 -> 12
30 -> 39
31 -> 11
32 -> 14
33 -> 16
34 -> 14
35 -> 19
36 -> 10
code-golf math
A pandigital number is one which contains every digit from 0 to 9 at least once. 1234567890, 1902837465000000, and 9023289761326634265 are all pandigital.
A diverse pair of numbers is a pair of numbers $(a, b)$ such that $a^b$ is pandigital. $b$ is called the diversifying exponent.
Challenge: Given a number $a$, find the smallest corresponding diversifying exponent $b$. This is a code-golf, so the shortest program in bytes wins.
(You may assume that there exists such an exponent, that is, your program will not be given invalid input, such as a power of 10.)
Your solution must be able to handle at the minimum the given test cases, but it should theoretically handle all valid inputs.
This is A090493 on OEIS.
Test cases
2 -> 68
3 -> 39
4 -> 34
5 -> 19
6 -> 20
7 -> 18
8 -> 28
9 -> 24
11 -> 23
12 -> 22
13 -> 22
14 -> 21
15 -> 12
16 -> 17
17 -> 14
18 -> 21
19 -> 17
20 -> 51
21 -> 17
22 -> 18
23 -> 14
24 -> 19
25 -> 11
26 -> 18
27 -> 13
28 -> 11
29 -> 12
30 -> 39
31 -> 11
32 -> 14
33 -> 16
34 -> 14
35 -> 19
36 -> 10
code-golf math
code-golf math
asked 2 hours ago
Conor O'Brien
29k263160
29k263160
1
I want to point out a special case1234567890 -> 1
.
– Bubbler
2 hours ago
add a comment |
1
I want to point out a special case1234567890 -> 1
.
– Bubbler
2 hours ago
1
1
I want to point out a special case
1234567890 -> 1
.– Bubbler
2 hours ago
I want to point out a special case
1234567890 -> 1
.– Bubbler
2 hours ago
add a comment |
5 Answers
5
active
oldest
votes
up vote
2
down vote
JavaScript (Node.js), 51 46 43 bytes
Takes input as a BigInt literal. Returns true instead of 1.
f=(n,k=n)=>new Set(n+'').size>9||1+f(n*k,k)
Try it online!
1
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
2
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
add a comment |
up vote
0
down vote
J, 25 bytes
>:@]^:(10>#@~.@":@^)^:_&1
Try it online!
Single monadic verb. The input should be an extended-precision integer (e.g. 2x
).
How it works
>:@]^:(10>#@~.@":@^)^:_&1 Monadic verb. Input: base a
^: ^:_ Good old do-while loop.
&1 Given 1 as the starting point for b,
>:@] increment it each step
( ) and continue while the condition is true:
":@^ Digits of a^b
~.@ Unique digits
#@ Count of unique digits
10> is less than 10
add a comment |
up vote
0
down vote
Jelly, 12 11 bytes
1*@ṾØDfƑʋ1#
Try it online!
How it works
1*@ṾØDfƑʋ1# Main link. Argument: n
1 Set the return value to 1.
1# Call the link to the left for k = 1, 2, ... and with right argument n,
until it returns a truthy value.
ʋ Combine the four links to the left into a dyadic chain.
*@ Compute n**k.
Ṿ Convert it to its string representation.
ØD Yield "0123456789".
fƑ Filter and return 1 is the result is equal to the left argument.
add a comment |
up vote
0
down vote
Perl 6, 32 bytes
{first ($_** *).comb.Set>9,1..*}
Try it online!
Pretty self-explanatory.
Explanation
{ } # Anonymous code block
first ,1..* # First positive number that
($_** *) # When the input is raised to that power
.comb.Set # The set of digits
>9 # Is longer than 9
add a comment |
up vote
0
down vote
Python 2, 44 bytes
f=lambda n,k=1:11>len(set(`k`))and-~f(n,n*k)
Input has to be a long, as `k`
behaves differently for longs and ints.
Try it online!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f177826%2fsmallest-diversifying-exponent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
JavaScript (Node.js), 51 46 43 bytes
Takes input as a BigInt literal. Returns true instead of 1.
f=(n,k=n)=>new Set(n+'').size>9||1+f(n*k,k)
Try it online!
1
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
2
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
add a comment |
up vote
2
down vote
JavaScript (Node.js), 51 46 43 bytes
Takes input as a BigInt literal. Returns true instead of 1.
f=(n,k=n)=>new Set(n+'').size>9||1+f(n*k,k)
Try it online!
1
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
2
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
add a comment |
up vote
2
down vote
up vote
2
down vote
JavaScript (Node.js), 51 46 43 bytes
Takes input as a BigInt literal. Returns true instead of 1.
f=(n,k=n)=>new Set(n+'').size>9||1+f(n*k,k)
Try it online!
JavaScript (Node.js), 51 46 43 bytes
Takes input as a BigInt literal. Returns true instead of 1.
f=(n,k=n)=>new Set(n+'').size>9||1+f(n*k,k)
Try it online!
edited 1 hour ago
answered 2 hours ago
Arnauld
71.9k688301
71.9k688301
1
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
2
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
add a comment |
1
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
2
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
1
1
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I keep forgetting JS has bigint's now :D
– Conor O'Brien
2 hours ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
I am slightly dubious regarding returning true instead of 1. That doesn't seem to match anything described at codegolf.meta.stackexchange.com/questions/9263/…
– Sparr
1 hour ago
2
2
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
@Sparr Here is the current consensus.
– Arnauld
1 hour ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
Thanks. I put a new Answer on my link referring to that.
– Sparr
46 mins ago
add a comment |
up vote
0
down vote
J, 25 bytes
>:@]^:(10>#@~.@":@^)^:_&1
Try it online!
Single monadic verb. The input should be an extended-precision integer (e.g. 2x
).
How it works
>:@]^:(10>#@~.@":@^)^:_&1 Monadic verb. Input: base a
^: ^:_ Good old do-while loop.
&1 Given 1 as the starting point for b,
>:@] increment it each step
( ) and continue while the condition is true:
":@^ Digits of a^b
~.@ Unique digits
#@ Count of unique digits
10> is less than 10
add a comment |
up vote
0
down vote
J, 25 bytes
>:@]^:(10>#@~.@":@^)^:_&1
Try it online!
Single monadic verb. The input should be an extended-precision integer (e.g. 2x
).
How it works
>:@]^:(10>#@~.@":@^)^:_&1 Monadic verb. Input: base a
^: ^:_ Good old do-while loop.
&1 Given 1 as the starting point for b,
>:@] increment it each step
( ) and continue while the condition is true:
":@^ Digits of a^b
~.@ Unique digits
#@ Count of unique digits
10> is less than 10
add a comment |
up vote
0
down vote
up vote
0
down vote
J, 25 bytes
>:@]^:(10>#@~.@":@^)^:_&1
Try it online!
Single monadic verb. The input should be an extended-precision integer (e.g. 2x
).
How it works
>:@]^:(10>#@~.@":@^)^:_&1 Monadic verb. Input: base a
^: ^:_ Good old do-while loop.
&1 Given 1 as the starting point for b,
>:@] increment it each step
( ) and continue while the condition is true:
":@^ Digits of a^b
~.@ Unique digits
#@ Count of unique digits
10> is less than 10
J, 25 bytes
>:@]^:(10>#@~.@":@^)^:_&1
Try it online!
Single monadic verb. The input should be an extended-precision integer (e.g. 2x
).
How it works
>:@]^:(10>#@~.@":@^)^:_&1 Monadic verb. Input: base a
^: ^:_ Good old do-while loop.
&1 Given 1 as the starting point for b,
>:@] increment it each step
( ) and continue while the condition is true:
":@^ Digits of a^b
~.@ Unique digits
#@ Count of unique digits
10> is less than 10
answered 2 hours ago
Bubbler
6,204759
6,204759
add a comment |
add a comment |
up vote
0
down vote
Jelly, 12 11 bytes
1*@ṾØDfƑʋ1#
Try it online!
How it works
1*@ṾØDfƑʋ1# Main link. Argument: n
1 Set the return value to 1.
1# Call the link to the left for k = 1, 2, ... and with right argument n,
until it returns a truthy value.
ʋ Combine the four links to the left into a dyadic chain.
*@ Compute n**k.
Ṿ Convert it to its string representation.
ØD Yield "0123456789".
fƑ Filter and return 1 is the result is equal to the left argument.
add a comment |
up vote
0
down vote
Jelly, 12 11 bytes
1*@ṾØDfƑʋ1#
Try it online!
How it works
1*@ṾØDfƑʋ1# Main link. Argument: n
1 Set the return value to 1.
1# Call the link to the left for k = 1, 2, ... and with right argument n,
until it returns a truthy value.
ʋ Combine the four links to the left into a dyadic chain.
*@ Compute n**k.
Ṿ Convert it to its string representation.
ØD Yield "0123456789".
fƑ Filter and return 1 is the result is equal to the left argument.
add a comment |
up vote
0
down vote
up vote
0
down vote
Jelly, 12 11 bytes
1*@ṾØDfƑʋ1#
Try it online!
How it works
1*@ṾØDfƑʋ1# Main link. Argument: n
1 Set the return value to 1.
1# Call the link to the left for k = 1, 2, ... and with right argument n,
until it returns a truthy value.
ʋ Combine the four links to the left into a dyadic chain.
*@ Compute n**k.
Ṿ Convert it to its string representation.
ØD Yield "0123456789".
fƑ Filter and return 1 is the result is equal to the left argument.
Jelly, 12 11 bytes
1*@ṾØDfƑʋ1#
Try it online!
How it works
1*@ṾØDfƑʋ1# Main link. Argument: n
1 Set the return value to 1.
1# Call the link to the left for k = 1, 2, ... and with right argument n,
until it returns a truthy value.
ʋ Combine the four links to the left into a dyadic chain.
*@ Compute n**k.
Ṿ Convert it to its string representation.
ØD Yield "0123456789".
fƑ Filter and return 1 is the result is equal to the left argument.
edited 1 hour ago
answered 1 hour ago
Dennis♦
186k32295735
186k32295735
add a comment |
add a comment |
up vote
0
down vote
Perl 6, 32 bytes
{first ($_** *).comb.Set>9,1..*}
Try it online!
Pretty self-explanatory.
Explanation
{ } # Anonymous code block
first ,1..* # First positive number that
($_** *) # When the input is raised to that power
.comb.Set # The set of digits
>9 # Is longer than 9
add a comment |
up vote
0
down vote
Perl 6, 32 bytes
{first ($_** *).comb.Set>9,1..*}
Try it online!
Pretty self-explanatory.
Explanation
{ } # Anonymous code block
first ,1..* # First positive number that
($_** *) # When the input is raised to that power
.comb.Set # The set of digits
>9 # Is longer than 9
add a comment |
up vote
0
down vote
up vote
0
down vote
Perl 6, 32 bytes
{first ($_** *).comb.Set>9,1..*}
Try it online!
Pretty self-explanatory.
Explanation
{ } # Anonymous code block
first ,1..* # First positive number that
($_** *) # When the input is raised to that power
.comb.Set # The set of digits
>9 # Is longer than 9
Perl 6, 32 bytes
{first ($_** *).comb.Set>9,1..*}
Try it online!
Pretty self-explanatory.
Explanation
{ } # Anonymous code block
first ,1..* # First positive number that
($_** *) # When the input is raised to that power
.comb.Set # The set of digits
>9 # Is longer than 9
edited 56 mins ago
answered 2 hours ago
Jo King
20.5k246108
20.5k246108
add a comment |
add a comment |
up vote
0
down vote
Python 2, 44 bytes
f=lambda n,k=1:11>len(set(`k`))and-~f(n,n*k)
Input has to be a long, as `k`
behaves differently for longs and ints.
Try it online!
add a comment |
up vote
0
down vote
Python 2, 44 bytes
f=lambda n,k=1:11>len(set(`k`))and-~f(n,n*k)
Input has to be a long, as `k`
behaves differently for longs and ints.
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
Python 2, 44 bytes
f=lambda n,k=1:11>len(set(`k`))and-~f(n,n*k)
Input has to be a long, as `k`
behaves differently for longs and ints.
Try it online!
Python 2, 44 bytes
f=lambda n,k=1:11>len(set(`k`))and-~f(n,n*k)
Input has to be a long, as `k`
behaves differently for longs and ints.
Try it online!
answered 38 mins ago
Dennis♦
186k32295735
186k32295735
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f177826%2fsmallest-diversifying-exponent%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
1
I want to point out a special case
1234567890 -> 1
.– Bubbler
2 hours ago