# Smallest Diversifying Exponent

A pandigital number is an integer which contains every digit from 0 to 9 at least once. 1234567890, 1902837465000000, and 9023289761326634265 are all pandigital. For the purposes of this challenge, numbers such as 123456789 are not pandigital, since they do not contain a 0, even though 123456789 = 0123456789.

A diverse pair of integers is a pair of integers $$\(a, b)\$$ such that $$\a^b\$$ is pandigital. $$\b\$$ is called the diversifying exponent.

Challenge: Given an integer $$\a\$$, find the smallest corresponding diversifying exponent $$\b\$$. This is a , 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
1234567890 -> 1

• I want to point out a special case 1234567890 -> 1. – Bubbler Dec 20 '18 at 0:48
• @Bubbler Added. – Conor O'Brien Dec 20 '18 at 3:03
• are negative exponents off limits? – sudo rm -rf slash Dec 20 '18 at 11:51
• Does something like 123456789 count as pandigital? It is equal to 0123456789, which is definitely pandigital. – wastl Dec 20 '18 at 18:08
• @wastl no, it does not. – Conor O'Brien Dec 20 '18 at 19:17

# Brachylog (v2), 9 bytes

;.≜^dl10∧


Try it online!

This is a function submission. The TIO link contains a wrapper that makes a function into a full program.

## Explanation

;.≜^dl10∧
.≜        Brute-force all integers, outputting the closest to 0
;  ^         for which {the input} to the power of the number
d        has a list of unique digits
l10     of length 10
∧  (turn off an unwanted implicit constraint)


# 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!

# 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


# 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!

• I keep forgetting JS has bigint's now :D – Conor O'Brien Dec 20 '18 at 0:44
• 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 Dec 20 '18 at 1:43
• @Sparr Here is the current consensus. – Arnauld Dec 20 '18 at 1:44
• Thanks. I put a new Answer on my link referring to that. – Sparr Dec 20 '18 at 2:04

# Ruby, 41 bytes

->n{i=0;i+=1until(n**i).digits.uniq;i}


Try it online!

f a=until(\b->all(elemshow(a^b))['0'..'9'])(+1)1


Try it online!

Same byte count:

f a=[b|b<-[1..],all(elemshow(a^b))['0'..'9']]!!0


# 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

• (]+10>#@=@":@^)^:_* – FrownyFrog Dec 26 '18 at 13:18

proc X d {while {[llength [lsort -u [split [expr $d**[incr i]] ""]]]-10} {} set i}  Try it online! • You can save some more bytes with llength 82 bytes – david Dec 20 '18 at 12:45 • Saved some bytes, thenks to @david – sergiol Dec 20 '18 at 14:02 # Racket, 110 96 bytes -14 bytes thanks to UltimateHawk! (define(f n[b 1])(if(= 10(length(remove-duplicates(string->list(~v(expt n b))))))b(f n(+ b 1))))  Try it online! • This can be shortened to 96 bytes by recursing on the function instead (define(f n[b 1])(if(= 10(length(remove-duplicates(string->list(~v(expt n b))))))b(f n(+ b 1)))) – Ultimate Hawk Dec 20 '18 at 14:23 • @UltimateHawk Thank you! I forgot about the default parameters...(although the helper function also used default parameter b...) – Galen Ivanov Dec 20 '18 at 14:31 # Python 3, 52 47 bytes thanks to @BMO f=lambda n,i=1:len({*str(n**i)})>9or 1+f(n,i+1)  Try it online! • Just a heads up but you can just remove old code and put "<s>52</s> 47" in the header line. The edit log will retain the old versions if anyone is curious – Veskah Dec 20 '18 at 21:01 # 05AB1E (legacy), 10 9 bytes Saved 1 byte thanks to Mr. Xcoder XµINmÙgTQ  Try it online! Explanation Xµ # find the first positive integer N that INm # when the input is raised to N Ù # and duplicate digits are removed g # has a length TQ # equal to 10  • Legacy saves 1 byte: 1µINmÙgTQTry it online! – Mr. Xcoder Dec 20 '18 at 21:49 • @Mr.Xcoder: Oh yeah, we had the implicit output of N then. Thanks! – Emigna Dec 20 '18 at 21:50 # Charcoal, 19 bytes ＷΦχ¬№ＩＸＩθＬυＩκ⊞υωＩＬυ  Try it online! Link is to verbose version of code. Explanation: ＷΦχ¬№ＩＸＩθＬυＩκ⊞υω  Repeatedly push the empty string to the empty list until there are no digits that the power of the input to the length of the list does not contain. ＩＬυ  Print the length of the list. • Why the downvote? – Luis Mendo Dec 20 '18 at 18:35 # K (ngn/k), 76 bytes {#{10>#?(+/|\0<|x)#x}{{+/2 99#,/|0 10\x,0}/+/99 99#,/a*\:x,0}\a::|(99#10)\x}  Try it online! { } function with argument x |(99#10)\x we represent numbers as reversed lists of 99 decimal digits - do that to the argument a:: assign to global variable a (k has no closures. we need a to be global so we can use it in subfunctions) { }{ }\ while the first function returns falsey, keep applying the second function (aka while loop), preserving intermediate results a*\:x each of a's digits multiplied by each of x's digits ("outer product") 99 99#a*\:x,0 add an extra column of 0s and reshape again to 99x99, this shifts the i-th row by i items to the right, inserting 0s on the left (this works for the tests, for larger inputs 99x99 might lead to overflows) +/ sum {+/2 99#,/|0 10\x,0}/ propagate carry: • { }/ keep applying until convergence • 0 10\x divmod by 10 (a pair of lists) • |0 10\x moddiv by 10 • 2 99#,/|0 10\x,0 moddiv by 10, with the "div" part shifted 1 digit to the right • +/ sum {10>#?(+/|\0<|x)#x} - check for (not) pandigital: • |x reverse x • 0< which digits are non-zero • |\ partial maxima • +/ sum - this counts the number of leading 0s in x • 10> are they fewer than 10? # length of the sequence of powers - this is the result # PowerShell, 107 bytes param([bigint]$a)for([bigint]$b=1;-join("$([bigint]::pow($a,$b))"|% t*y|sort -u)-ne-join(0..9);$b=$b+1){}$b  Try it online! Pretty straightforward, just a shame we need to use [bigint] everywhere. We take input $a, then setup a for loop with initializer $b=1. Each iteration we increment $b after checking whether $a ^$b (via pow) sent toCharArray, sorted with the -unique flag, then -joined together into a string is -notequal to the range 0..9 also -joined into a string.

That's a mouthful. For example, this would compare 7 ^ 5 = 16807 --> "01678" against "0123456789", determine they're not equal, and continue the loop.

Once we're out of the loop, we've determined which $b suits our input, and so leave that on the pipeline. Output is implicit. # Java, 108 bytes a->{int b=0;while(new java.math.BigDecimal(a).pow(++b).toString().chars().distinct().count()<10);return b;};  Try it online! Explanation Brute force, looping a^b until it finds a string with 10 (or more, but that's impossible as there will only be 0 through 9) unique characters. BigDecimal is required both because Math.pow is not accurate enough (fails on case 11), and also because converting a Double to a String by default shows scientific notation, which breaks this method of finding a pandigital number. • Don't Java vars start at 0 by default? Could save 2 bytes by eliminating the initialization. – Darrel Hoffman Dec 20 '18 at 22:13 • @DarrelHoffman Instance variables do, yes. Locally-scoped variables do not. – Hypino Dec 20 '18 at 22:17 • Ah, alright. Been some time since I worked in Java, forgot that technicality. – Darrel Hoffman Dec 21 '18 at 13:27 • You can save 6 bytes by changing new java.math.BigDecimal(a).pow(++b).toString() to (new java.math.BigDecimal(a).pow(++b)+"") (and the trailing semi-colon doesn't have to be counted for lambda functions). Try it online – Kevin Cruijssen Dec 22 '18 at 16:39 # Pyth, 10 8 bytes fq;l{^Q  Try it online here. fq;l{^QT Implicit: Q=eval(input()) Trailing T inferred f Return (and print) the first positive integer where the following is true: ^QT Raise input to the current number-th power  Convert to string { Deduplicate l Take the length q Is the above equal to... ; 10  Saved 2 bytes thanks to FryAmTheEggman, previous code fq;l{j^QT; • You can use backtick to convert the number to a string instead of doing base conversion which will let you leave out the T in the power operation. – FryAmTheEggman Dec 20 '18 at 15:30 # 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.  # Clean, 107 101 bytes import StdEnv,Data.Integer$a=hd[b\\b<-[1..]|length(removeDup[c\\c<-:toString(prod(repeatn b a))])>9]


Try it online!

Takes input as Integer, returns Int

# Wolfram Language (Mathematica), 48 bytes

(For[n=1,!AllTrue[DigitCount[#^n],#>0&],n++];n)&


Try it online!

# Attache, 27 bytes

${ } lambda, input: x Generate{ } first natural number _ satisfying... x^_ the input to that number Unique[ ] unique digits of ^ # length of ^ >9 is greater than 9 i.e.: has 10 distinct digits  ## Alternatives 28 bytes: ${Generate{Unique@S[x^_]@9}}

29 bytes: ${Generate{Unique[S[x^_]]@9}} 30 bytes: ${Generate{#Unique[S[x^_]]>9}}

31 bytes: Generate@${{#Unique[S[x^_]]>9}} 32 bytes: ${Generate[{#Unique[S[x^_]]>9}]}

33 bytes: ${If[#Unique[x^y]>9,y,x&$!-~y]}&0

34 bytes: ${If[#Unique[x^y]>9,y,$[x,y+1]]}&0`