Self-contained powers











up vote
13
down vote

favorite












Given integer n, output the smallest exponent e greater than 1 such that n^e contains n as a substring.



For example, for 25, the answer should be 2, as 25 ^ 2 = 625, which contains 25 as a substring, but the answer for 13 should be 10, as 13 ^ 10 = 137858491849, so 10 is the lowest exponent for which the result contains 13 as a substring.



Rules




  • Standard I/O rules

  • Standard loopholes apply

  • Shortest code in bytes wins


  • n will always be an integer greater than 0


Test Cases



1 => 2   (1 ^ 2 = 1)
2 => 5 (2 ^ 5 = 32)
3 => 5 (3 ^ 5 = 243)
4 => 3 (4 ^ 3 = 64)
5 => 2 (5 ^ 2 = 25)
6 => 2 (6 ^ 2 = 36)
7 => 5 (7 ^ 5 = 16807)
8 => 5 (8 ^ 5 = 32768)
9 => 3 (9 ^ 3 = 729)
10 => 2 (10 ^ 2 = 100)
11 => 11 (11 ^ 11 = 285311670611)
12 => 14 (12 ^ 14 = 1283918464548864)
13 => 10 (13 ^ 10 = 137858491849)
14 => 8 (14 ^ 8 = 1475789056)
15 => 26 (15 ^ 26 = 3787675244106352329254150390625)
16 => 6 (16 ^ 6 = 16777216)
17 => 17 (17 ^ 17 = 827240261886336764177)
18 => 5 (18 ^ 5 = 1889568)
19 => 11 (19 ^ 11 = 116490258898219)
20 => 5 (20 ^ 5 = 3200000)
25 => 2 (25 ^ 2 = 625)
30 => 5 (30 ^ 5 = 24300000)
35 => 10 (35 ^ 10 = 2758547353515625)
40 => 3 (40 ^ 3 = 64000)
45 => 5 (45 ^ 5 = 184528125)
50 => 2 (50 ^ 2 = 2500)
55 => 11 (55 ^ 11 = 13931233916552734375)
60 => 2 (60 ^ 2 = 3600)
65 => 17 (65 ^ 17 = 6599743590836592050933837890625)
70 => 5 (70 ^ 5 = 1680700000)
75 => 3 (75 ^ 3 = 421875)
80 => 5 (80 ^ 5 = 3276800000)
85 => 22 (85 ^ 22 = 2800376120856162211833149645328521728515625)
90 => 3 (90 ^ 3 = 729000)
95 => 13 (95 ^ 13 = 51334208327950511474609375)
100 => 2 (100 ^ 2 = 10000)


Python script to generate the first 1000 answers










share|improve this question






















  • Related
    – Skidsdev
    Nov 28 at 18:07










  • A045537
    – Shaggy
    Nov 28 at 19:55















up vote
13
down vote

favorite












Given integer n, output the smallest exponent e greater than 1 such that n^e contains n as a substring.



For example, for 25, the answer should be 2, as 25 ^ 2 = 625, which contains 25 as a substring, but the answer for 13 should be 10, as 13 ^ 10 = 137858491849, so 10 is the lowest exponent for which the result contains 13 as a substring.



Rules




  • Standard I/O rules

  • Standard loopholes apply

  • Shortest code in bytes wins


  • n will always be an integer greater than 0


Test Cases



1 => 2   (1 ^ 2 = 1)
2 => 5 (2 ^ 5 = 32)
3 => 5 (3 ^ 5 = 243)
4 => 3 (4 ^ 3 = 64)
5 => 2 (5 ^ 2 = 25)
6 => 2 (6 ^ 2 = 36)
7 => 5 (7 ^ 5 = 16807)
8 => 5 (8 ^ 5 = 32768)
9 => 3 (9 ^ 3 = 729)
10 => 2 (10 ^ 2 = 100)
11 => 11 (11 ^ 11 = 285311670611)
12 => 14 (12 ^ 14 = 1283918464548864)
13 => 10 (13 ^ 10 = 137858491849)
14 => 8 (14 ^ 8 = 1475789056)
15 => 26 (15 ^ 26 = 3787675244106352329254150390625)
16 => 6 (16 ^ 6 = 16777216)
17 => 17 (17 ^ 17 = 827240261886336764177)
18 => 5 (18 ^ 5 = 1889568)
19 => 11 (19 ^ 11 = 116490258898219)
20 => 5 (20 ^ 5 = 3200000)
25 => 2 (25 ^ 2 = 625)
30 => 5 (30 ^ 5 = 24300000)
35 => 10 (35 ^ 10 = 2758547353515625)
40 => 3 (40 ^ 3 = 64000)
45 => 5 (45 ^ 5 = 184528125)
50 => 2 (50 ^ 2 = 2500)
55 => 11 (55 ^ 11 = 13931233916552734375)
60 => 2 (60 ^ 2 = 3600)
65 => 17 (65 ^ 17 = 6599743590836592050933837890625)
70 => 5 (70 ^ 5 = 1680700000)
75 => 3 (75 ^ 3 = 421875)
80 => 5 (80 ^ 5 = 3276800000)
85 => 22 (85 ^ 22 = 2800376120856162211833149645328521728515625)
90 => 3 (90 ^ 3 = 729000)
95 => 13 (95 ^ 13 = 51334208327950511474609375)
100 => 2 (100 ^ 2 = 10000)


Python script to generate the first 1000 answers










share|improve this question






















  • Related
    – Skidsdev
    Nov 28 at 18:07










  • A045537
    – Shaggy
    Nov 28 at 19:55













up vote
13
down vote

favorite









up vote
13
down vote

favorite











Given integer n, output the smallest exponent e greater than 1 such that n^e contains n as a substring.



For example, for 25, the answer should be 2, as 25 ^ 2 = 625, which contains 25 as a substring, but the answer for 13 should be 10, as 13 ^ 10 = 137858491849, so 10 is the lowest exponent for which the result contains 13 as a substring.



Rules




  • Standard I/O rules

  • Standard loopholes apply

  • Shortest code in bytes wins


  • n will always be an integer greater than 0


Test Cases



1 => 2   (1 ^ 2 = 1)
2 => 5 (2 ^ 5 = 32)
3 => 5 (3 ^ 5 = 243)
4 => 3 (4 ^ 3 = 64)
5 => 2 (5 ^ 2 = 25)
6 => 2 (6 ^ 2 = 36)
7 => 5 (7 ^ 5 = 16807)
8 => 5 (8 ^ 5 = 32768)
9 => 3 (9 ^ 3 = 729)
10 => 2 (10 ^ 2 = 100)
11 => 11 (11 ^ 11 = 285311670611)
12 => 14 (12 ^ 14 = 1283918464548864)
13 => 10 (13 ^ 10 = 137858491849)
14 => 8 (14 ^ 8 = 1475789056)
15 => 26 (15 ^ 26 = 3787675244106352329254150390625)
16 => 6 (16 ^ 6 = 16777216)
17 => 17 (17 ^ 17 = 827240261886336764177)
18 => 5 (18 ^ 5 = 1889568)
19 => 11 (19 ^ 11 = 116490258898219)
20 => 5 (20 ^ 5 = 3200000)
25 => 2 (25 ^ 2 = 625)
30 => 5 (30 ^ 5 = 24300000)
35 => 10 (35 ^ 10 = 2758547353515625)
40 => 3 (40 ^ 3 = 64000)
45 => 5 (45 ^ 5 = 184528125)
50 => 2 (50 ^ 2 = 2500)
55 => 11 (55 ^ 11 = 13931233916552734375)
60 => 2 (60 ^ 2 = 3600)
65 => 17 (65 ^ 17 = 6599743590836592050933837890625)
70 => 5 (70 ^ 5 = 1680700000)
75 => 3 (75 ^ 3 = 421875)
80 => 5 (80 ^ 5 = 3276800000)
85 => 22 (85 ^ 22 = 2800376120856162211833149645328521728515625)
90 => 3 (90 ^ 3 = 729000)
95 => 13 (95 ^ 13 = 51334208327950511474609375)
100 => 2 (100 ^ 2 = 10000)


Python script to generate the first 1000 answers










share|improve this question













Given integer n, output the smallest exponent e greater than 1 such that n^e contains n as a substring.



For example, for 25, the answer should be 2, as 25 ^ 2 = 625, which contains 25 as a substring, but the answer for 13 should be 10, as 13 ^ 10 = 137858491849, so 10 is the lowest exponent for which the result contains 13 as a substring.



Rules




  • Standard I/O rules

  • Standard loopholes apply

  • Shortest code in bytes wins


  • n will always be an integer greater than 0


Test Cases



1 => 2   (1 ^ 2 = 1)
2 => 5 (2 ^ 5 = 32)
3 => 5 (3 ^ 5 = 243)
4 => 3 (4 ^ 3 = 64)
5 => 2 (5 ^ 2 = 25)
6 => 2 (6 ^ 2 = 36)
7 => 5 (7 ^ 5 = 16807)
8 => 5 (8 ^ 5 = 32768)
9 => 3 (9 ^ 3 = 729)
10 => 2 (10 ^ 2 = 100)
11 => 11 (11 ^ 11 = 285311670611)
12 => 14 (12 ^ 14 = 1283918464548864)
13 => 10 (13 ^ 10 = 137858491849)
14 => 8 (14 ^ 8 = 1475789056)
15 => 26 (15 ^ 26 = 3787675244106352329254150390625)
16 => 6 (16 ^ 6 = 16777216)
17 => 17 (17 ^ 17 = 827240261886336764177)
18 => 5 (18 ^ 5 = 1889568)
19 => 11 (19 ^ 11 = 116490258898219)
20 => 5 (20 ^ 5 = 3200000)
25 => 2 (25 ^ 2 = 625)
30 => 5 (30 ^ 5 = 24300000)
35 => 10 (35 ^ 10 = 2758547353515625)
40 => 3 (40 ^ 3 = 64000)
45 => 5 (45 ^ 5 = 184528125)
50 => 2 (50 ^ 2 = 2500)
55 => 11 (55 ^ 11 = 13931233916552734375)
60 => 2 (60 ^ 2 = 3600)
65 => 17 (65 ^ 17 = 6599743590836592050933837890625)
70 => 5 (70 ^ 5 = 1680700000)
75 => 3 (75 ^ 3 = 421875)
80 => 5 (80 ^ 5 = 3276800000)
85 => 22 (85 ^ 22 = 2800376120856162211833149645328521728515625)
90 => 3 (90 ^ 3 = 729000)
95 => 13 (95 ^ 13 = 51334208327950511474609375)
100 => 2 (100 ^ 2 = 10000)


Python script to generate the first 1000 answers







code-golf number






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 at 18:07









Skidsdev

6,1682870




6,1682870












  • Related
    – Skidsdev
    Nov 28 at 18:07










  • A045537
    – Shaggy
    Nov 28 at 19:55


















  • Related
    – Skidsdev
    Nov 28 at 18:07










  • A045537
    – Shaggy
    Nov 28 at 19:55
















Related
– Skidsdev
Nov 28 at 18:07




Related
– Skidsdev
Nov 28 at 18:07












A045537
– Shaggy
Nov 28 at 19:55




A045537
– Shaggy
Nov 28 at 19:55










26 Answers
26






active

oldest

votes

















up vote
4
down vote














Perl 6, 31 bytes



{$^a;first {$a**$_~~/$a/},2..*}


Try it online!






share|improve this answer




























    up vote
    4
    down vote














    R, 69 44 bytes





    function(n,i=2){while(!grepl(n,n^i))i=i+1;i}


    Anonymous function. Works on large i when n is converted to BigZ (see TIO). Thanks for teaching me something Giuseppe and digEmAll!



    Try it online!






    share|improve this answer























    • 61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
      – Giuseppe
      Nov 28 at 19:57










    • 56 bytes -- returning i should be sufficient.
      – Giuseppe
      Nov 28 at 19:58






    • 2




      44 bytes paste is not necessary, grepl converts to character by default :)
      – digEmAll
      Nov 29 at 7:54












    • The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
      – digEmAll
      Nov 29 at 8:12






    • 1




      @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
      – Giuseppe
      Nov 29 at 23:51


















    up vote
    3
    down vote














    Python 2, 42 41 bytes



    -1 byte thanks to Ørjan Johansen (returning y directely)





    f=lambda x,y=2:y*(`x`in`x**y`)or f(x,y+1)


    Try it online!



    Explanation/Ungolfed



    Recursive function trying from $2,3dots$ until we succeed:



    # Start recursion with y=2
    def f(x,y=2):
    # If we succeed, we arrived at the desired y
    if `x` in `x**y`:
    return y
    # Else we try with next y
    else:
    return f(x, y+1)


    Try it online!






    share|improve this answer



















    • 1




      Returning y is shorter
      – Ørjan Johansen
      Nov 28 at 21:44










    • @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
      – BMO
      Nov 28 at 22:03










    • I had to swap the multiplication to avoid a space, maybe that was it?
      – Ørjan Johansen
      Nov 28 at 22:26










    • @ØrjanJohansen: Probably that was it, yeah.
      – BMO
      Nov 29 at 0:04


















    up vote
    3
    down vote













    JavaScript (ES6 / Node.js),  41  40 bytes



    Saved 1 byte thanks to @Shaggy



    Takes input as a Number (works for $n<15$) or a BigInt literal.





    n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)


    Try it online!






    share|improve this answer



















    • 1




      Ended up with a solution very similar to yours for 40 bytes
      – Shaggy
      Nov 28 at 20:13










    • @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
      – Luis felipe De jesus Munoz
      Nov 28 at 20:17








    • 1




      @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
      – Shaggy
      Nov 28 at 20:19










    • Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
      – Shieru Asakoto
      Nov 29 at 7:53












    • @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
      – Arnauld
      Nov 29 at 8:11


















    up vote
    3
    down vote














    APL (Dyalog Unicode), 25 23 17 bytes



    -2 bytes thanks to @Erik the Outgolfer



    -6 bytes thanks to @ngn



    thanks to @H.PWiz for making the code not require a custom ⎕pp (print precision)





    ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨


    Try it online!



    ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨
    ×⍣( )⍨ generates a geometric progression by repeatedly multiplying the argument
    by its original value
    ∨/(⍕÷)⍷0⍕⊣ the progression stops when this function, applied between the new and the
    last old member, returns true
    ÷ the original argument (ratio between two consecutive members)
    ⍕ formatted as a string
    ⍷ occurrences within...
    0⍕ ...the formatted (with 0 digits after the decimal point)...
    ⊣ ...new member
    ∨/ are there any?
    ⊢⍟ use logarithm to determine what power of ⍵ we reached





    share|improve this answer























    • This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
      – Cows quack
      Nov 28 at 19:07










    • @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
      – Quintec
      Nov 28 at 19:09










    • Oh wait that won't even work
      – Quintec
      Nov 28 at 19:10










    • 23 bytes.
      – Erik the Outgolfer
      Nov 28 at 20:44










    • 19 bytes
      – ngn
      Nov 28 at 21:19




















    up vote
    2
    down vote














    Pyth, 9 bytes



    f}`Q`^QT2


    Try it online!






    share|improve this answer




























      up vote
      2
      down vote














      05AB1E, 7 bytes



      ∞>.Δm¹å


      Try it online!



      Explanation:



      ∞>.Δm¹å  //full program
      ∞ //push infinite list, stack = [1,2,3...]
      > //increment, stack is now [2,3,4...]
      .Δ //find the first item N that satisfies the following
      ¹ //input
      å //is in
      m //(implicit) input ** N





      share|improve this answer






























        up vote
        2
        down vote













        SAS, 71 66 bytes



        Edit: Removed ;run; at the end, since it's implied by the end of inputs.



        data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;


        Input data is entered after the cards; statement, like so:



        data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14


        Generates a dataset a containing the input n and the output e.



        enter image description here






        share|improve this answer























        • This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
          – Skidsdev
          Nov 29 at 20:28










        • @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
          – Josh Eller
          Nov 29 at 20:56




















        up vote
        1
        down vote














        Jelly, 7 bytes



        2ẇ*¥@1#


        Try it online!






        share|improve this answer




























          up vote
          1
          down vote














          Clean, 99 bytes



          import StdEnv,Text,Data.Integer
          $n=hd[p\p<-[fromInt 2..]|indexOf(""<+n)(""<+prod(repeatn p n))>=0]


          Try it online!



          If it doesn't need to work for giant huge numbers, then




          Clean, 64 bytes



          import StdEnv,Text
          $n=hd[p\p<-[2..]|indexOf(""<+n)(""<+n^p)>=0]


          Try it online!






          share|improve this answer




























            up vote
            1
            down vote














            Brachylog, 8 bytes



            ;.^s?∧ℕ₂


            Try it online!



            Explanation



            ;.^         Input ^ Output…
            s? …contains the Input as a substring…
            ∧ …and…
            ℕ₂ …the Output is in [2,+∞)





            share|improve this answer




























              up vote
              1
              down vote














              Java (OpenJDK 8), 84 bytes



              Takes input as a String representing the number and outputs an int.



              Most of the bytes come from the verbosity of the BigDecimal being needed to process the large numbers.





              n->{int i=1;while(!(new java.math.BigDecimal(n).pow(++i)+"").contains(n));return i;}


              Try it online!





              How it works



              This is fairly simple but I'll include the explanation for posterity;



              n->{                                    // Lamdba taking a String and returning an int
              int i=1; // Initialises the count
              while(! // Loops and increments until
              (new java.math.BigDecimal(n) // Creates a new BigDecimal from the input n
              .pow(++i)+"") // Raises it to the power of the current count
              .contains(n) // If that contains the input, end the loop
              );
              return i; // Return the count
              }





              share|improve this answer




























                up vote
                0
                down vote














                Ruby, 37 bytes





                ->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}


                Try it online!






                share|improve this answer




























                  up vote
                  0
                  down vote













                  Japt, 10 bytes



                  @pX søU}a2


                  Try it






                  share|improve this answer




























                    up vote
                    0
                    down vote














                    JavaScript (Node.js), 45 bytes





                    Test cases taken from @Arnauld's answer



                    a=>eval("for(i=1n;!(''+a**++i).match(a););i")


                    Try it online!






                    share|improve this answer






























                      up vote
                      0
                      down vote














                      Charcoal, 19 bytes



                      W∨‹Lυ²¬№IΠυθ⊞υIθILυ


                      Try it online! Link is to verbose version of code. Explanation:



                      W∨‹Lυ²¬№IΠυθ⊞


                      Repeat until the the list length is at least 2 and its product contains the input...



                      ⊞υIθ


                      ... cast the input to integer and push it to the list.



                      ILυ


                      Cast the length of the list to string and implicitly print it.






                      share|improve this answer




























                        up vote
                        0
                        down vote














                        Python 3, 63 58 bytes





                        def f(n,e=2):
                        while str(n)not in str(n**e):e+=1
                        return e


                        Try it online!



                        Python2 would probably be shorter, but I like using 3. Coming up wiht a lambda is difficult, but I'm trying a few things.






                        share|improve this answer























                        • I dont know python but, isn't it shorter using lambda?
                          – Luis felipe De jesus Munoz
                          Nov 28 at 20:05










                        • @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                          – Gigaflop
                          Nov 28 at 20:07










                        • Maybe some recursive function?
                          – Luis felipe De jesus Munoz
                          Nov 28 at 20:10






                        • 2




                          Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                          – BMO
                          Nov 28 at 20:38










                        • @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                          – DJMcMayhem
                          Nov 28 at 20:44


















                        up vote
                        0
                        down vote














                        MathGolf, 10 bytes



                        ôkï⌠#k╧▼ï⌠


                        Try it online!



                        Explanation



                        This feels extremely wasteful, having to read the input explicitly twice, having to increment the loop counter twice.



                        ô            start block of length 6
                        k read integer from input
                        ï index of current loop, or length of last loop
                        ⌠ increment twice
                        # pop a, b : push(a**b)
                        k read integer from input
                        ╧ pop a, b, a.contains(b)
                        ▼ do while false with pop
                        ï index of current loop, or length of last loop
                        ⌠ increment twice





                        share|improve this answer




























                          up vote
                          0
                          down vote














                          Ruby, 41 bytes





                          f=->n,a=n{(a*=n).to_s=~/#{n}/?2:1+f[n,a]}


                          Try it online!






                          share|improve this answer




























                            up vote
                            0
                            down vote














                            C# (.NET Core), 104 89 bytes





                            a=>{int i=2;while(!(System.Numerics.BigInteger.Pow(a,i)+"").Contains(a+""))i++;return i;}


                            Try it online!



                            -1 byte: changed for loop to while (thanks to Skidsdev)
                            -14 bytes: abused C#'s weird string handling to remove ToString() calls



                            Need to use C#'s BigInteger library, as the standard numeric C# types (int, double, long, ulong, etc.) fail for some larger numbers (including 12, 15, and 17).



                            Ungolfed:



                            a => {
                            int i = 2; // initialize i

                            while( !(System.Numerics.BigInteger.Pow(a,i) + "") // n = a^i, convert to string
                            .Contains(a + "")) // if n doesn't contain a
                            i++; // increment i

                            return i;
                            }





                            share|improve this answer























                            • You can save 1 byte by switching to a while loop
                              – Skidsdev
                              Nov 29 at 13:53


















                            up vote
                            0
                            down vote














                            Python 2, 47 bytes





                            i,e=input(),2
                            while`i`not in`i**e`:e+=1
                            print e


                            Try it online!



                            Inspired by @Gigaflop's solution.






                            share|improve this answer




























                              up vote
                              0
                              down vote














                              Tcl, 69 81 bytes



                              proc S n {incr i
                              while {![regexp $n [expr $n**[incr i]]]} {}
                              puts $i}


                              Try it online!






                              share|improve this answer























                              • Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                – sergiol
                                Nov 29 at 23:22


















                              up vote
                              0
                              down vote













                              PowerShell(V3+), 67 bytes



                              function f{param($n)$i=1;do{}until([math]::pow($n,++$i)-match$n)$i}





                              share|improve this answer




























                                up vote
                                0
                                down vote













                                Common Lisp, 78 bytes



                                (lambda(n)(do((e 2(1+ e)))((search(format()"~d"n)(format()"~d"(expt n e)))e)))


                                Try it online!






                                share|improve this answer




























                                  up vote
                                  0
                                  down vote














                                  J, 26 bytes



                                  2>:@]^:(0=[+/@E.&":^)^:_~]


                                  Try it online!



                                  NOTE: I've changed the final ] to x: in the TIO, to make the tests pass for larger integers.






                                  share|improve this answer




























                                    up vote
                                    0
                                    down vote













                                    Oracle SQL, 68 bytes



                                    select max(level)+1 from dual,t connect by instr(power(x,level),x)=0


                                    There is an assumption that source number is stored in a table t(x), e.g.



                                    with t as (select 95 x from dual)


                                    Test in SQL*Plus



                                    SQL> with t as (select 95 x from dual)
                                    2 select max(level)+1 from dual,t connect by instr(power(x,level),x)=0
                                    3 /

                                    MAX(LEVEL)+1
                                    ------------
                                    13





                                    share|improve this answer





















                                      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',
                                      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
                                      });


                                      }
                                      });














                                      draft saved

                                      draft discarded


















                                      StackExchange.ready(
                                      function () {
                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176734%2fself-contained-powers%23new-answer', 'question_page');
                                      }
                                      );

                                      Post as a guest















                                      Required, but never shown

























                                      26 Answers
                                      26






                                      active

                                      oldest

                                      votes








                                      26 Answers
                                      26






                                      active

                                      oldest

                                      votes









                                      active

                                      oldest

                                      votes






                                      active

                                      oldest

                                      votes








                                      up vote
                                      4
                                      down vote














                                      Perl 6, 31 bytes



                                      {$^a;first {$a**$_~~/$a/},2..*}


                                      Try it online!






                                      share|improve this answer

























                                        up vote
                                        4
                                        down vote














                                        Perl 6, 31 bytes



                                        {$^a;first {$a**$_~~/$a/},2..*}


                                        Try it online!






                                        share|improve this answer























                                          up vote
                                          4
                                          down vote










                                          up vote
                                          4
                                          down vote










                                          Perl 6, 31 bytes



                                          {$^a;first {$a**$_~~/$a/},2..*}


                                          Try it online!






                                          share|improve this answer













                                          Perl 6, 31 bytes



                                          {$^a;first {$a**$_~~/$a/},2..*}


                                          Try it online!







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Nov 28 at 18:41









                                          Sean

                                          3,28636




                                          3,28636






















                                              up vote
                                              4
                                              down vote














                                              R, 69 44 bytes





                                              function(n,i=2){while(!grepl(n,n^i))i=i+1;i}


                                              Anonymous function. Works on large i when n is converted to BigZ (see TIO). Thanks for teaching me something Giuseppe and digEmAll!



                                              Try it online!






                                              share|improve this answer























                                              • 61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
                                                – Giuseppe
                                                Nov 28 at 19:57










                                              • 56 bytes -- returning i should be sufficient.
                                                – Giuseppe
                                                Nov 28 at 19:58






                                              • 2




                                                44 bytes paste is not necessary, grepl converts to character by default :)
                                                – digEmAll
                                                Nov 29 at 7:54












                                              • The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
                                                – digEmAll
                                                Nov 29 at 8:12






                                              • 1




                                                @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
                                                – Giuseppe
                                                Nov 29 at 23:51















                                              up vote
                                              4
                                              down vote














                                              R, 69 44 bytes





                                              function(n,i=2){while(!grepl(n,n^i))i=i+1;i}


                                              Anonymous function. Works on large i when n is converted to BigZ (see TIO). Thanks for teaching me something Giuseppe and digEmAll!



                                              Try it online!






                                              share|improve this answer























                                              • 61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
                                                – Giuseppe
                                                Nov 28 at 19:57










                                              • 56 bytes -- returning i should be sufficient.
                                                – Giuseppe
                                                Nov 28 at 19:58






                                              • 2




                                                44 bytes paste is not necessary, grepl converts to character by default :)
                                                – digEmAll
                                                Nov 29 at 7:54












                                              • The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
                                                – digEmAll
                                                Nov 29 at 8:12






                                              • 1




                                                @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
                                                – Giuseppe
                                                Nov 29 at 23:51













                                              up vote
                                              4
                                              down vote










                                              up vote
                                              4
                                              down vote










                                              R, 69 44 bytes





                                              function(n,i=2){while(!grepl(n,n^i))i=i+1;i}


                                              Anonymous function. Works on large i when n is converted to BigZ (see TIO). Thanks for teaching me something Giuseppe and digEmAll!



                                              Try it online!






                                              share|improve this answer















                                              R, 69 44 bytes





                                              function(n,i=2){while(!grepl(n,n^i))i=i+1;i}


                                              Anonymous function. Works on large i when n is converted to BigZ (see TIO). Thanks for teaching me something Giuseppe and digEmAll!



                                              Try it online!







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 30 at 16:37

























                                              answered Nov 28 at 19:36









                                              BLT

                                              876412




                                              876412












                                              • 61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
                                                – Giuseppe
                                                Nov 28 at 19:57










                                              • 56 bytes -- returning i should be sufficient.
                                                – Giuseppe
                                                Nov 28 at 19:58






                                              • 2




                                                44 bytes paste is not necessary, grepl converts to character by default :)
                                                – digEmAll
                                                Nov 29 at 7:54












                                              • The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
                                                – digEmAll
                                                Nov 29 at 8:12






                                              • 1




                                                @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
                                                – Giuseppe
                                                Nov 29 at 23:51


















                                              • 61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
                                                – Giuseppe
                                                Nov 28 at 19:57










                                              • 56 bytes -- returning i should be sufficient.
                                                – Giuseppe
                                                Nov 28 at 19:58






                                              • 2




                                                44 bytes paste is not necessary, grepl converts to character by default :)
                                                – digEmAll
                                                Nov 29 at 7:54












                                              • The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
                                                – digEmAll
                                                Nov 29 at 8:12






                                              • 1




                                                @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
                                                – Giuseppe
                                                Nov 29 at 23:51
















                                              61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
                                              – Giuseppe
                                              Nov 28 at 19:57




                                              61 bytes -- you had an extra space in n, ?n^i and paste converts to character by default :-)
                                              – Giuseppe
                                              Nov 28 at 19:57












                                              56 bytes -- returning i should be sufficient.
                                              – Giuseppe
                                              Nov 28 at 19:58




                                              56 bytes -- returning i should be sufficient.
                                              – Giuseppe
                                              Nov 28 at 19:58




                                              2




                                              2




                                              44 bytes paste is not necessary, grepl converts to character by default :)
                                              – digEmAll
                                              Nov 29 at 7:54






                                              44 bytes paste is not necessary, grepl converts to character by default :)
                                              – digEmAll
                                              Nov 29 at 7:54














                                              The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
                                              – digEmAll
                                              Nov 29 at 8:12




                                              The problem is that it is "faulty" when exponents become big because of floating points accuracy and the fact that big numbers are converted to string in scientific notation. For instance 15 returns 17 while it should be 26. So, theoretically this works, but in practice we should use a Big Integer package or something like that...
                                              – digEmAll
                                              Nov 29 at 8:12




                                              1




                                              1




                                              @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
                                              – Giuseppe
                                              Nov 29 at 23:51




                                              @digEmAll for BigInt you could just force input to be a bigInt like BigZ from gmp and it should still work, except possibly for converting i to a bigZ as well
                                              – Giuseppe
                                              Nov 29 at 23:51










                                              up vote
                                              3
                                              down vote














                                              Python 2, 42 41 bytes



                                              -1 byte thanks to Ørjan Johansen (returning y directely)





                                              f=lambda x,y=2:y*(`x`in`x**y`)or f(x,y+1)


                                              Try it online!



                                              Explanation/Ungolfed



                                              Recursive function trying from $2,3dots$ until we succeed:



                                              # Start recursion with y=2
                                              def f(x,y=2):
                                              # If we succeed, we arrived at the desired y
                                              if `x` in `x**y`:
                                              return y
                                              # Else we try with next y
                                              else:
                                              return f(x, y+1)


                                              Try it online!






                                              share|improve this answer



















                                              • 1




                                                Returning y is shorter
                                                – Ørjan Johansen
                                                Nov 28 at 21:44










                                              • @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
                                                – BMO
                                                Nov 28 at 22:03










                                              • I had to swap the multiplication to avoid a space, maybe that was it?
                                                – Ørjan Johansen
                                                Nov 28 at 22:26










                                              • @ØrjanJohansen: Probably that was it, yeah.
                                                – BMO
                                                Nov 29 at 0:04















                                              up vote
                                              3
                                              down vote














                                              Python 2, 42 41 bytes



                                              -1 byte thanks to Ørjan Johansen (returning y directely)





                                              f=lambda x,y=2:y*(`x`in`x**y`)or f(x,y+1)


                                              Try it online!



                                              Explanation/Ungolfed



                                              Recursive function trying from $2,3dots$ until we succeed:



                                              # Start recursion with y=2
                                              def f(x,y=2):
                                              # If we succeed, we arrived at the desired y
                                              if `x` in `x**y`:
                                              return y
                                              # Else we try with next y
                                              else:
                                              return f(x, y+1)


                                              Try it online!






                                              share|improve this answer



















                                              • 1




                                                Returning y is shorter
                                                – Ørjan Johansen
                                                Nov 28 at 21:44










                                              • @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
                                                – BMO
                                                Nov 28 at 22:03










                                              • I had to swap the multiplication to avoid a space, maybe that was it?
                                                – Ørjan Johansen
                                                Nov 28 at 22:26










                                              • @ØrjanJohansen: Probably that was it, yeah.
                                                – BMO
                                                Nov 29 at 0:04













                                              up vote
                                              3
                                              down vote










                                              up vote
                                              3
                                              down vote










                                              Python 2, 42 41 bytes



                                              -1 byte thanks to Ørjan Johansen (returning y directely)





                                              f=lambda x,y=2:y*(`x`in`x**y`)or f(x,y+1)


                                              Try it online!



                                              Explanation/Ungolfed



                                              Recursive function trying from $2,3dots$ until we succeed:



                                              # Start recursion with y=2
                                              def f(x,y=2):
                                              # If we succeed, we arrived at the desired y
                                              if `x` in `x**y`:
                                              return y
                                              # Else we try with next y
                                              else:
                                              return f(x, y+1)


                                              Try it online!






                                              share|improve this answer















                                              Python 2, 42 41 bytes



                                              -1 byte thanks to Ørjan Johansen (returning y directely)





                                              f=lambda x,y=2:y*(`x`in`x**y`)or f(x,y+1)


                                              Try it online!



                                              Explanation/Ungolfed



                                              Recursive function trying from $2,3dots$ until we succeed:



                                              # Start recursion with y=2
                                              def f(x,y=2):
                                              # If we succeed, we arrived at the desired y
                                              if `x` in `x**y`:
                                              return y
                                              # Else we try with next y
                                              else:
                                              return f(x, y+1)


                                              Try it online!







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 28 at 22:02

























                                              answered Nov 28 at 20:38









                                              BMO

                                              11k21881




                                              11k21881








                                              • 1




                                                Returning y is shorter
                                                – Ørjan Johansen
                                                Nov 28 at 21:44










                                              • @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
                                                – BMO
                                                Nov 28 at 22:03










                                              • I had to swap the multiplication to avoid a space, maybe that was it?
                                                – Ørjan Johansen
                                                Nov 28 at 22:26










                                              • @ØrjanJohansen: Probably that was it, yeah.
                                                – BMO
                                                Nov 29 at 0:04














                                              • 1




                                                Returning y is shorter
                                                – Ørjan Johansen
                                                Nov 28 at 21:44










                                              • @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
                                                – BMO
                                                Nov 28 at 22:03










                                              • I had to swap the multiplication to avoid a space, maybe that was it?
                                                – Ørjan Johansen
                                                Nov 28 at 22:26










                                              • @ØrjanJohansen: Probably that was it, yeah.
                                                – BMO
                                                Nov 29 at 0:04








                                              1




                                              1




                                              Returning y is shorter
                                              – Ørjan Johansen
                                              Nov 28 at 21:44




                                              Returning y is shorter
                                              – Ørjan Johansen
                                              Nov 28 at 21:44












                                              @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
                                              – BMO
                                              Nov 28 at 22:03




                                              @ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
                                              – BMO
                                              Nov 28 at 22:03












                                              I had to swap the multiplication to avoid a space, maybe that was it?
                                              – Ørjan Johansen
                                              Nov 28 at 22:26




                                              I had to swap the multiplication to avoid a space, maybe that was it?
                                              – Ørjan Johansen
                                              Nov 28 at 22:26












                                              @ØrjanJohansen: Probably that was it, yeah.
                                              – BMO
                                              Nov 29 at 0:04




                                              @ØrjanJohansen: Probably that was it, yeah.
                                              – BMO
                                              Nov 29 at 0:04










                                              up vote
                                              3
                                              down vote













                                              JavaScript (ES6 / Node.js),  41  40 bytes



                                              Saved 1 byte thanks to @Shaggy



                                              Takes input as a Number (works for $n<15$) or a BigInt literal.





                                              n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)


                                              Try it online!






                                              share|improve this answer



















                                              • 1




                                                Ended up with a solution very similar to yours for 40 bytes
                                                – Shaggy
                                                Nov 28 at 20:13










                                              • @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
                                                – Luis felipe De jesus Munoz
                                                Nov 28 at 20:17








                                              • 1




                                                @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
                                                – Shaggy
                                                Nov 28 at 20:19










                                              • Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
                                                – Shieru Asakoto
                                                Nov 29 at 7:53












                                              • @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
                                                – Arnauld
                                                Nov 29 at 8:11















                                              up vote
                                              3
                                              down vote













                                              JavaScript (ES6 / Node.js),  41  40 bytes



                                              Saved 1 byte thanks to @Shaggy



                                              Takes input as a Number (works for $n<15$) or a BigInt literal.





                                              n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)


                                              Try it online!






                                              share|improve this answer



















                                              • 1




                                                Ended up with a solution very similar to yours for 40 bytes
                                                – Shaggy
                                                Nov 28 at 20:13










                                              • @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
                                                – Luis felipe De jesus Munoz
                                                Nov 28 at 20:17








                                              • 1




                                                @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
                                                – Shaggy
                                                Nov 28 at 20:19










                                              • Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
                                                – Shieru Asakoto
                                                Nov 29 at 7:53












                                              • @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
                                                – Arnauld
                                                Nov 29 at 8:11













                                              up vote
                                              3
                                              down vote










                                              up vote
                                              3
                                              down vote









                                              JavaScript (ES6 / Node.js),  41  40 bytes



                                              Saved 1 byte thanks to @Shaggy



                                              Takes input as a Number (works for $n<15$) or a BigInt literal.





                                              n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)


                                              Try it online!






                                              share|improve this answer














                                              JavaScript (ES6 / Node.js),  41  40 bytes



                                              Saved 1 byte thanks to @Shaggy



                                              Takes input as a Number (works for $n<15$) or a BigInt literal.





                                              n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)


                                              Try it online!







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 29 at 8:08

























                                              answered Nov 28 at 18:30









                                              Arnauld

                                              71.1k688298




                                              71.1k688298








                                              • 1




                                                Ended up with a solution very similar to yours for 40 bytes
                                                – Shaggy
                                                Nov 28 at 20:13










                                              • @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
                                                – Luis felipe De jesus Munoz
                                                Nov 28 at 20:17








                                              • 1




                                                @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
                                                – Shaggy
                                                Nov 28 at 20:19










                                              • Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
                                                – Shieru Asakoto
                                                Nov 29 at 7:53












                                              • @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
                                                – Arnauld
                                                Nov 29 at 8:11














                                              • 1




                                                Ended up with a solution very similar to yours for 40 bytes
                                                – Shaggy
                                                Nov 28 at 20:13










                                              • @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
                                                – Luis felipe De jesus Munoz
                                                Nov 28 at 20:17








                                              • 1




                                                @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
                                                – Shaggy
                                                Nov 28 at 20:19










                                              • Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
                                                – Shieru Asakoto
                                                Nov 29 at 7:53












                                              • @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
                                                – Arnauld
                                                Nov 29 at 8:11








                                              1




                                              1




                                              Ended up with a solution very similar to yours for 40 bytes
                                              – Shaggy
                                              Nov 28 at 20:13




                                              Ended up with a solution very similar to yours for 40 bytes
                                              – Shaggy
                                              Nov 28 at 20:13












                                              @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
                                              – Luis felipe De jesus Munoz
                                              Nov 28 at 20:17






                                              @Shaggy You need to use big integers, otherwise it wont return the correct answer in some test cases. At the end it has the same bytecount n=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
                                              – Luis felipe De jesus Munoz
                                              Nov 28 at 20:17






                                              1




                                              1




                                              @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
                                              – Shaggy
                                              Nov 28 at 20:19




                                              @LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
                                              – Shaggy
                                              Nov 28 at 20:19












                                              Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
                                              – Shieru Asakoto
                                              Nov 29 at 7:53






                                              Minor thing but if this uses BigInt shouldn't the title be JavaScript (Node.js)? ES6 doesn't have BigInt yet.
                                              – Shieru Asakoto
                                              Nov 29 at 7:53














                                              @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
                                              – Arnauld
                                              Nov 29 at 8:11




                                              @ShieruAsakoto You're right. My initial intention was to explain that it works with either a Number or a BigInt. Now clarified.
                                              – Arnauld
                                              Nov 29 at 8:11










                                              up vote
                                              3
                                              down vote














                                              APL (Dyalog Unicode), 25 23 17 bytes



                                              -2 bytes thanks to @Erik the Outgolfer



                                              -6 bytes thanks to @ngn



                                              thanks to @H.PWiz for making the code not require a custom ⎕pp (print precision)





                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨


                                              Try it online!



                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨
                                              ×⍣( )⍨ generates a geometric progression by repeatedly multiplying the argument
                                              by its original value
                                              ∨/(⍕÷)⍷0⍕⊣ the progression stops when this function, applied between the new and the
                                              last old member, returns true
                                              ÷ the original argument (ratio between two consecutive members)
                                              ⍕ formatted as a string
                                              ⍷ occurrences within...
                                              0⍕ ...the formatted (with 0 digits after the decimal point)...
                                              ⊣ ...new member
                                              ∨/ are there any?
                                              ⊢⍟ use logarithm to determine what power of ⍵ we reached





                                              share|improve this answer























                                              • This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
                                                – Cows quack
                                                Nov 28 at 19:07










                                              • @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
                                                – Quintec
                                                Nov 28 at 19:09










                                              • Oh wait that won't even work
                                                – Quintec
                                                Nov 28 at 19:10










                                              • 23 bytes.
                                                – Erik the Outgolfer
                                                Nov 28 at 20:44










                                              • 19 bytes
                                                – ngn
                                                Nov 28 at 21:19

















                                              up vote
                                              3
                                              down vote














                                              APL (Dyalog Unicode), 25 23 17 bytes



                                              -2 bytes thanks to @Erik the Outgolfer



                                              -6 bytes thanks to @ngn



                                              thanks to @H.PWiz for making the code not require a custom ⎕pp (print precision)





                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨


                                              Try it online!



                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨
                                              ×⍣( )⍨ generates a geometric progression by repeatedly multiplying the argument
                                              by its original value
                                              ∨/(⍕÷)⍷0⍕⊣ the progression stops when this function, applied between the new and the
                                              last old member, returns true
                                              ÷ the original argument (ratio between two consecutive members)
                                              ⍕ formatted as a string
                                              ⍷ occurrences within...
                                              0⍕ ...the formatted (with 0 digits after the decimal point)...
                                              ⊣ ...new member
                                              ∨/ are there any?
                                              ⊢⍟ use logarithm to determine what power of ⍵ we reached





                                              share|improve this answer























                                              • This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
                                                – Cows quack
                                                Nov 28 at 19:07










                                              • @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
                                                – Quintec
                                                Nov 28 at 19:09










                                              • Oh wait that won't even work
                                                – Quintec
                                                Nov 28 at 19:10










                                              • 23 bytes.
                                                – Erik the Outgolfer
                                                Nov 28 at 20:44










                                              • 19 bytes
                                                – ngn
                                                Nov 28 at 21:19















                                              up vote
                                              3
                                              down vote










                                              up vote
                                              3
                                              down vote










                                              APL (Dyalog Unicode), 25 23 17 bytes



                                              -2 bytes thanks to @Erik the Outgolfer



                                              -6 bytes thanks to @ngn



                                              thanks to @H.PWiz for making the code not require a custom ⎕pp (print precision)





                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨


                                              Try it online!



                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨
                                              ×⍣( )⍨ generates a geometric progression by repeatedly multiplying the argument
                                              by its original value
                                              ∨/(⍕÷)⍷0⍕⊣ the progression stops when this function, applied between the new and the
                                              last old member, returns true
                                              ÷ the original argument (ratio between two consecutive members)
                                              ⍕ formatted as a string
                                              ⍷ occurrences within...
                                              0⍕ ...the formatted (with 0 digits after the decimal point)...
                                              ⊣ ...new member
                                              ∨/ are there any?
                                              ⊢⍟ use logarithm to determine what power of ⍵ we reached





                                              share|improve this answer















                                              APL (Dyalog Unicode), 25 23 17 bytes



                                              -2 bytes thanks to @Erik the Outgolfer



                                              -6 bytes thanks to @ngn



                                              thanks to @H.PWiz for making the code not require a custom ⎕pp (print precision)





                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨


                                              Try it online!



                                              ⊢⍟×⍣(∨/(⍕÷)⍷0⍕⊣)⍨
                                              ×⍣( )⍨ generates a geometric progression by repeatedly multiplying the argument
                                              by its original value
                                              ∨/(⍕÷)⍷0⍕⊣ the progression stops when this function, applied between the new and the
                                              last old member, returns true
                                              ÷ the original argument (ratio between two consecutive members)
                                              ⍕ formatted as a string
                                              ⍷ occurrences within...
                                              0⍕ ...the formatted (with 0 digits after the decimal point)...
                                              ⊣ ...new member
                                              ∨/ are there any?
                                              ⊢⍟ use logarithm to determine what power of ⍵ we reached






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 29 at 15:59

























                                              answered Nov 28 at 18:54









                                              Quintec

                                              1,3051519




                                              1,3051519












                                              • This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
                                                – Cows quack
                                                Nov 28 at 19:07










                                              • @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
                                                – Quintec
                                                Nov 28 at 19:09










                                              • Oh wait that won't even work
                                                – Quintec
                                                Nov 28 at 19:10










                                              • 23 bytes.
                                                – Erik the Outgolfer
                                                Nov 28 at 20:44










                                              • 19 bytes
                                                – ngn
                                                Nov 28 at 21:19




















                                              • This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
                                                – Cows quack
                                                Nov 28 at 19:07










                                              • @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
                                                – Quintec
                                                Nov 28 at 19:09










                                              • Oh wait that won't even work
                                                – Quintec
                                                Nov 28 at 19:10










                                              • 23 bytes.
                                                – Erik the Outgolfer
                                                Nov 28 at 20:44










                                              • 19 bytes
                                                – ngn
                                                Nov 28 at 21:19


















                                              This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
                                              – Cows quack
                                              Nov 28 at 19:07




                                              This fails for 17 because it it finds 17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support
                                              – Cows quack
                                              Nov 28 at 19:07












                                              @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
                                              – Quintec
                                              Nov 28 at 19:09




                                              @Cowsquack I just have to arbitrarily adjust ⎕PP I guess
                                              – Quintec
                                              Nov 28 at 19:09












                                              Oh wait that won't even work
                                              – Quintec
                                              Nov 28 at 19:10




                                              Oh wait that won't even work
                                              – Quintec
                                              Nov 28 at 19:10












                                              23 bytes.
                                              – Erik the Outgolfer
                                              Nov 28 at 20:44




                                              23 bytes.
                                              – Erik the Outgolfer
                                              Nov 28 at 20:44












                                              19 bytes
                                              – ngn
                                              Nov 28 at 21:19






                                              19 bytes
                                              – ngn
                                              Nov 28 at 21:19












                                              up vote
                                              2
                                              down vote














                                              Pyth, 9 bytes



                                              f}`Q`^QT2


                                              Try it online!






                                              share|improve this answer

























                                                up vote
                                                2
                                                down vote














                                                Pyth, 9 bytes



                                                f}`Q`^QT2


                                                Try it online!






                                                share|improve this answer























                                                  up vote
                                                  2
                                                  down vote










                                                  up vote
                                                  2
                                                  down vote










                                                  Pyth, 9 bytes



                                                  f}`Q`^QT2


                                                  Try it online!






                                                  share|improve this answer













                                                  Pyth, 9 bytes



                                                  f}`Q`^QT2


                                                  Try it online!







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Nov 28 at 18:55









                                                  lirtosiast

                                                  15.6k436107




                                                  15.6k436107






















                                                      up vote
                                                      2
                                                      down vote














                                                      05AB1E, 7 bytes



                                                      ∞>.Δm¹å


                                                      Try it online!



                                                      Explanation:



                                                      ∞>.Δm¹å  //full program
                                                      ∞ //push infinite list, stack = [1,2,3...]
                                                      > //increment, stack is now [2,3,4...]
                                                      .Δ //find the first item N that satisfies the following
                                                      ¹ //input
                                                      å //is in
                                                      m //(implicit) input ** N





                                                      share|improve this answer



























                                                        up vote
                                                        2
                                                        down vote














                                                        05AB1E, 7 bytes



                                                        ∞>.Δm¹å


                                                        Try it online!



                                                        Explanation:



                                                        ∞>.Δm¹å  //full program
                                                        ∞ //push infinite list, stack = [1,2,3...]
                                                        > //increment, stack is now [2,3,4...]
                                                        .Δ //find the first item N that satisfies the following
                                                        ¹ //input
                                                        å //is in
                                                        m //(implicit) input ** N





                                                        share|improve this answer

























                                                          up vote
                                                          2
                                                          down vote










                                                          up vote
                                                          2
                                                          down vote










                                                          05AB1E, 7 bytes



                                                          ∞>.Δm¹å


                                                          Try it online!



                                                          Explanation:



                                                          ∞>.Δm¹å  //full program
                                                          ∞ //push infinite list, stack = [1,2,3...]
                                                          > //increment, stack is now [2,3,4...]
                                                          .Δ //find the first item N that satisfies the following
                                                          ¹ //input
                                                          å //is in
                                                          m //(implicit) input ** N





                                                          share|improve this answer















                                                          05AB1E, 7 bytes



                                                          ∞>.Δm¹å


                                                          Try it online!



                                                          Explanation:



                                                          ∞>.Δm¹å  //full program
                                                          ∞ //push infinite list, stack = [1,2,3...]
                                                          > //increment, stack is now [2,3,4...]
                                                          .Δ //find the first item N that satisfies the following
                                                          ¹ //input
                                                          å //is in
                                                          m //(implicit) input ** N






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Nov 29 at 14:39

























                                                          answered Nov 28 at 21:52









                                                          Cowabunghole

                                                          1,050418




                                                          1,050418






















                                                              up vote
                                                              2
                                                              down vote













                                                              SAS, 71 66 bytes



                                                              Edit: Removed ;run; at the end, since it's implied by the end of inputs.



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;


                                                              Input data is entered after the cards; statement, like so:



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;
                                                              1
                                                              2
                                                              3
                                                              4
                                                              5
                                                              6
                                                              7
                                                              8
                                                              9
                                                              10
                                                              11
                                                              12
                                                              13
                                                              14


                                                              Generates a dataset a containing the input n and the output e.



                                                              enter image description here






                                                              share|improve this answer























                                                              • This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
                                                                – Skidsdev
                                                                Nov 29 at 20:28










                                                              • @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
                                                                – Josh Eller
                                                                Nov 29 at 20:56

















                                                              up vote
                                                              2
                                                              down vote













                                                              SAS, 71 66 bytes



                                                              Edit: Removed ;run; at the end, since it's implied by the end of inputs.



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;


                                                              Input data is entered after the cards; statement, like so:



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;
                                                              1
                                                              2
                                                              3
                                                              4
                                                              5
                                                              6
                                                              7
                                                              8
                                                              9
                                                              10
                                                              11
                                                              12
                                                              13
                                                              14


                                                              Generates a dataset a containing the input n and the output e.



                                                              enter image description here






                                                              share|improve this answer























                                                              • This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
                                                                – Skidsdev
                                                                Nov 29 at 20:28










                                                              • @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
                                                                – Josh Eller
                                                                Nov 29 at 20:56















                                                              up vote
                                                              2
                                                              down vote










                                                              up vote
                                                              2
                                                              down vote









                                                              SAS, 71 66 bytes



                                                              Edit: Removed ;run; at the end, since it's implied by the end of inputs.



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;


                                                              Input data is entered after the cards; statement, like so:



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;
                                                              1
                                                              2
                                                              3
                                                              4
                                                              5
                                                              6
                                                              7
                                                              8
                                                              9
                                                              10
                                                              11
                                                              12
                                                              13
                                                              14


                                                              Generates a dataset a containing the input n and the output e.



                                                              enter image description here






                                                              share|improve this answer














                                                              SAS, 71 66 bytes



                                                              Edit: Removed ;run; at the end, since it's implied by the end of inputs.



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;


                                                              Input data is entered after the cards; statement, like so:



                                                              data a;input n;e=1;do until(find(cat(n**e),cat(n)));e+1;end;cards;
                                                              1
                                                              2
                                                              3
                                                              4
                                                              5
                                                              6
                                                              7
                                                              8
                                                              9
                                                              10
                                                              11
                                                              12
                                                              13
                                                              14


                                                              Generates a dataset a containing the input n and the output e.



                                                              enter image description here







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Nov 29 at 21:18

























                                                              answered Nov 29 at 20:26









                                                              Josh Eller

                                                              1913




                                                              1913












                                                              • This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
                                                                – Skidsdev
                                                                Nov 29 at 20:28










                                                              • @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
                                                                – Josh Eller
                                                                Nov 29 at 20:56




















                                                              • This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
                                                                – Skidsdev
                                                                Nov 29 at 20:28










                                                              • @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
                                                                – Josh Eller
                                                                Nov 29 at 20:56


















                                                              This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
                                                              – Skidsdev
                                                              Nov 29 at 20:28




                                                              This looks to be a function definition, or equivalent (I assume actually a "macro") This means that requiring it be called with arguments (ie %p(n)) is totally fine, however output depends on whether macros in SAS can return values. If they can return, the "output" should be by returning the result, otherwise it should output it by whatever standard output method is supported
                                                              – Skidsdev
                                                              Nov 29 at 20:28












                                                              @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
                                                              – Josh Eller
                                                              Nov 29 at 20:56






                                                              @Skidsdev Thanks for the feedback! SAS is a bit weird; macros aren't really functions, they're just a text substitution language that generates 'real' SAS code when compiled. I had a look at how other people have done I/O for SAS in codegolf, and edited my answer based on that, getting rid of the macro statements.
                                                              – Josh Eller
                                                              Nov 29 at 20:56












                                                              up vote
                                                              1
                                                              down vote














                                                              Jelly, 7 bytes



                                                              2ẇ*¥@1#


                                                              Try it online!






                                                              share|improve this answer

























                                                                up vote
                                                                1
                                                                down vote














                                                                Jelly, 7 bytes



                                                                2ẇ*¥@1#


                                                                Try it online!






                                                                share|improve this answer























                                                                  up vote
                                                                  1
                                                                  down vote










                                                                  up vote
                                                                  1
                                                                  down vote










                                                                  Jelly, 7 bytes



                                                                  2ẇ*¥@1#


                                                                  Try it online!






                                                                  share|improve this answer













                                                                  Jelly, 7 bytes



                                                                  2ẇ*¥@1#


                                                                  Try it online!







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Nov 28 at 20:05









                                                                  Erik the Outgolfer

                                                                  31k429102




                                                                  31k429102






















                                                                      up vote
                                                                      1
                                                                      down vote














                                                                      Clean, 99 bytes



                                                                      import StdEnv,Text,Data.Integer
                                                                      $n=hd[p\p<-[fromInt 2..]|indexOf(""<+n)(""<+prod(repeatn p n))>=0]


                                                                      Try it online!



                                                                      If it doesn't need to work for giant huge numbers, then




                                                                      Clean, 64 bytes



                                                                      import StdEnv,Text
                                                                      $n=hd[p\p<-[2..]|indexOf(""<+n)(""<+n^p)>=0]


                                                                      Try it online!






                                                                      share|improve this answer

























                                                                        up vote
                                                                        1
                                                                        down vote














                                                                        Clean, 99 bytes



                                                                        import StdEnv,Text,Data.Integer
                                                                        $n=hd[p\p<-[fromInt 2..]|indexOf(""<+n)(""<+prod(repeatn p n))>=0]


                                                                        Try it online!



                                                                        If it doesn't need to work for giant huge numbers, then




                                                                        Clean, 64 bytes



                                                                        import StdEnv,Text
                                                                        $n=hd[p\p<-[2..]|indexOf(""<+n)(""<+n^p)>=0]


                                                                        Try it online!






                                                                        share|improve this answer























                                                                          up vote
                                                                          1
                                                                          down vote










                                                                          up vote
                                                                          1
                                                                          down vote










                                                                          Clean, 99 bytes



                                                                          import StdEnv,Text,Data.Integer
                                                                          $n=hd[p\p<-[fromInt 2..]|indexOf(""<+n)(""<+prod(repeatn p n))>=0]


                                                                          Try it online!



                                                                          If it doesn't need to work for giant huge numbers, then




                                                                          Clean, 64 bytes



                                                                          import StdEnv,Text
                                                                          $n=hd[p\p<-[2..]|indexOf(""<+n)(""<+n^p)>=0]


                                                                          Try it online!






                                                                          share|improve this answer













                                                                          Clean, 99 bytes



                                                                          import StdEnv,Text,Data.Integer
                                                                          $n=hd[p\p<-[fromInt 2..]|indexOf(""<+n)(""<+prod(repeatn p n))>=0]


                                                                          Try it online!



                                                                          If it doesn't need to work for giant huge numbers, then




                                                                          Clean, 64 bytes



                                                                          import StdEnv,Text
                                                                          $n=hd[p\p<-[2..]|indexOf(""<+n)(""<+n^p)>=0]


                                                                          Try it online!







                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Nov 28 at 23:24









                                                                          Οurous

                                                                          6,12311032




                                                                          6,12311032






















                                                                              up vote
                                                                              1
                                                                              down vote














                                                                              Brachylog, 8 bytes



                                                                              ;.^s?∧ℕ₂


                                                                              Try it online!



                                                                              Explanation



                                                                              ;.^         Input ^ Output…
                                                                              s? …contains the Input as a substring…
                                                                              ∧ …and…
                                                                              ℕ₂ …the Output is in [2,+∞)





                                                                              share|improve this answer

























                                                                                up vote
                                                                                1
                                                                                down vote














                                                                                Brachylog, 8 bytes



                                                                                ;.^s?∧ℕ₂


                                                                                Try it online!



                                                                                Explanation



                                                                                ;.^         Input ^ Output…
                                                                                s? …contains the Input as a substring…
                                                                                ∧ …and…
                                                                                ℕ₂ …the Output is in [2,+∞)





                                                                                share|improve this answer























                                                                                  up vote
                                                                                  1
                                                                                  down vote










                                                                                  up vote
                                                                                  1
                                                                                  down vote










                                                                                  Brachylog, 8 bytes



                                                                                  ;.^s?∧ℕ₂


                                                                                  Try it online!



                                                                                  Explanation



                                                                                  ;.^         Input ^ Output…
                                                                                  s? …contains the Input as a substring…
                                                                                  ∧ …and…
                                                                                  ℕ₂ …the Output is in [2,+∞)





                                                                                  share|improve this answer













                                                                                  Brachylog, 8 bytes



                                                                                  ;.^s?∧ℕ₂


                                                                                  Try it online!



                                                                                  Explanation



                                                                                  ;.^         Input ^ Output…
                                                                                  s? …contains the Input as a substring…
                                                                                  ∧ …and…
                                                                                  ℕ₂ …the Output is in [2,+∞)






                                                                                  share|improve this answer












                                                                                  share|improve this answer



                                                                                  share|improve this answer










                                                                                  answered Nov 29 at 10:33









                                                                                  Fatalize

                                                                                  26.9k448134




                                                                                  26.9k448134






















                                                                                      up vote
                                                                                      1
                                                                                      down vote














                                                                                      Java (OpenJDK 8), 84 bytes



                                                                                      Takes input as a String representing the number and outputs an int.



                                                                                      Most of the bytes come from the verbosity of the BigDecimal being needed to process the large numbers.





                                                                                      n->{int i=1;while(!(new java.math.BigDecimal(n).pow(++i)+"").contains(n));return i;}


                                                                                      Try it online!





                                                                                      How it works



                                                                                      This is fairly simple but I'll include the explanation for posterity;



                                                                                      n->{                                    // Lamdba taking a String and returning an int
                                                                                      int i=1; // Initialises the count
                                                                                      while(! // Loops and increments until
                                                                                      (new java.math.BigDecimal(n) // Creates a new BigDecimal from the input n
                                                                                      .pow(++i)+"") // Raises it to the power of the current count
                                                                                      .contains(n) // If that contains the input, end the loop
                                                                                      );
                                                                                      return i; // Return the count
                                                                                      }





                                                                                      share|improve this answer

























                                                                                        up vote
                                                                                        1
                                                                                        down vote














                                                                                        Java (OpenJDK 8), 84 bytes



                                                                                        Takes input as a String representing the number and outputs an int.



                                                                                        Most of the bytes come from the verbosity of the BigDecimal being needed to process the large numbers.





                                                                                        n->{int i=1;while(!(new java.math.BigDecimal(n).pow(++i)+"").contains(n));return i;}


                                                                                        Try it online!





                                                                                        How it works



                                                                                        This is fairly simple but I'll include the explanation for posterity;



                                                                                        n->{                                    // Lamdba taking a String and returning an int
                                                                                        int i=1; // Initialises the count
                                                                                        while(! // Loops and increments until
                                                                                        (new java.math.BigDecimal(n) // Creates a new BigDecimal from the input n
                                                                                        .pow(++i)+"") // Raises it to the power of the current count
                                                                                        .contains(n) // If that contains the input, end the loop
                                                                                        );
                                                                                        return i; // Return the count
                                                                                        }





                                                                                        share|improve this answer























                                                                                          up vote
                                                                                          1
                                                                                          down vote










                                                                                          up vote
                                                                                          1
                                                                                          down vote










                                                                                          Java (OpenJDK 8), 84 bytes



                                                                                          Takes input as a String representing the number and outputs an int.



                                                                                          Most of the bytes come from the verbosity of the BigDecimal being needed to process the large numbers.





                                                                                          n->{int i=1;while(!(new java.math.BigDecimal(n).pow(++i)+"").contains(n));return i;}


                                                                                          Try it online!





                                                                                          How it works



                                                                                          This is fairly simple but I'll include the explanation for posterity;



                                                                                          n->{                                    // Lamdba taking a String and returning an int
                                                                                          int i=1; // Initialises the count
                                                                                          while(! // Loops and increments until
                                                                                          (new java.math.BigDecimal(n) // Creates a new BigDecimal from the input n
                                                                                          .pow(++i)+"") // Raises it to the power of the current count
                                                                                          .contains(n) // If that contains the input, end the loop
                                                                                          );
                                                                                          return i; // Return the count
                                                                                          }





                                                                                          share|improve this answer













                                                                                          Java (OpenJDK 8), 84 bytes



                                                                                          Takes input as a String representing the number and outputs an int.



                                                                                          Most of the bytes come from the verbosity of the BigDecimal being needed to process the large numbers.





                                                                                          n->{int i=1;while(!(new java.math.BigDecimal(n).pow(++i)+"").contains(n));return i;}


                                                                                          Try it online!





                                                                                          How it works



                                                                                          This is fairly simple but I'll include the explanation for posterity;



                                                                                          n->{                                    // Lamdba taking a String and returning an int
                                                                                          int i=1; // Initialises the count
                                                                                          while(! // Loops and increments until
                                                                                          (new java.math.BigDecimal(n) // Creates a new BigDecimal from the input n
                                                                                          .pow(++i)+"") // Raises it to the power of the current count
                                                                                          .contains(n) // If that contains the input, end the loop
                                                                                          );
                                                                                          return i; // Return the count
                                                                                          }






                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Nov 30 at 12:41









                                                                                          Luke Stevens

                                                                                          744214




                                                                                          744214






















                                                                                              up vote
                                                                                              0
                                                                                              down vote














                                                                                              Ruby, 37 bytes





                                                                                              ->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}


                                                                                              Try it online!






                                                                                              share|improve this answer

























                                                                                                up vote
                                                                                                0
                                                                                                down vote














                                                                                                Ruby, 37 bytes





                                                                                                ->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}


                                                                                                Try it online!






                                                                                                share|improve this answer























                                                                                                  up vote
                                                                                                  0
                                                                                                  down vote










                                                                                                  up vote
                                                                                                  0
                                                                                                  down vote










                                                                                                  Ruby, 37 bytes





                                                                                                  ->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}


                                                                                                  Try it online!






                                                                                                  share|improve this answer













                                                                                                  Ruby, 37 bytes





                                                                                                  ->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}


                                                                                                  Try it online!







                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Nov 28 at 18:43









                                                                                                  Kirill L.

                                                                                                  3,4351118




                                                                                                  3,4351118






















                                                                                                      up vote
                                                                                                      0
                                                                                                      down vote













                                                                                                      Japt, 10 bytes



                                                                                                      @pX søU}a2


                                                                                                      Try it






                                                                                                      share|improve this answer

























                                                                                                        up vote
                                                                                                        0
                                                                                                        down vote













                                                                                                        Japt, 10 bytes



                                                                                                        @pX søU}a2


                                                                                                        Try it






                                                                                                        share|improve this answer























                                                                                                          up vote
                                                                                                          0
                                                                                                          down vote










                                                                                                          up vote
                                                                                                          0
                                                                                                          down vote









                                                                                                          Japt, 10 bytes



                                                                                                          @pX søU}a2


                                                                                                          Try it






                                                                                                          share|improve this answer












                                                                                                          Japt, 10 bytes



                                                                                                          @pX søU}a2


                                                                                                          Try it







                                                                                                          share|improve this answer












                                                                                                          share|improve this answer



                                                                                                          share|improve this answer










                                                                                                          answered Nov 28 at 18:53









                                                                                                          Shaggy

                                                                                                          18.6k21663




                                                                                                          18.6k21663






















                                                                                                              up vote
                                                                                                              0
                                                                                                              down vote














                                                                                                              JavaScript (Node.js), 45 bytes





                                                                                                              Test cases taken from @Arnauld's answer



                                                                                                              a=>eval("for(i=1n;!(''+a**++i).match(a););i")


                                                                                                              Try it online!






                                                                                                              share|improve this answer



























                                                                                                                up vote
                                                                                                                0
                                                                                                                down vote














                                                                                                                JavaScript (Node.js), 45 bytes





                                                                                                                Test cases taken from @Arnauld's answer



                                                                                                                a=>eval("for(i=1n;!(''+a**++i).match(a););i")


                                                                                                                Try it online!






                                                                                                                share|improve this answer

























                                                                                                                  up vote
                                                                                                                  0
                                                                                                                  down vote










                                                                                                                  up vote
                                                                                                                  0
                                                                                                                  down vote










                                                                                                                  JavaScript (Node.js), 45 bytes





                                                                                                                  Test cases taken from @Arnauld's answer



                                                                                                                  a=>eval("for(i=1n;!(''+a**++i).match(a););i")


                                                                                                                  Try it online!






                                                                                                                  share|improve this answer















                                                                                                                  JavaScript (Node.js), 45 bytes





                                                                                                                  Test cases taken from @Arnauld's answer



                                                                                                                  a=>eval("for(i=1n;!(''+a**++i).match(a););i")


                                                                                                                  Try it online!







                                                                                                                  share|improve this answer














                                                                                                                  share|improve this answer



                                                                                                                  share|improve this answer








                                                                                                                  edited Nov 28 at 19:56









                                                                                                                  Shaggy

                                                                                                                  18.6k21663




                                                                                                                  18.6k21663










                                                                                                                  answered Nov 28 at 18:31









                                                                                                                  Luis felipe De jesus Munoz

                                                                                                                  4,02921254




                                                                                                                  4,02921254






















                                                                                                                      up vote
                                                                                                                      0
                                                                                                                      down vote














                                                                                                                      Charcoal, 19 bytes



                                                                                                                      W∨‹Lυ²¬№IΠυθ⊞υIθILυ


                                                                                                                      Try it online! Link is to verbose version of code. Explanation:



                                                                                                                      W∨‹Lυ²¬№IΠυθ⊞


                                                                                                                      Repeat until the the list length is at least 2 and its product contains the input...



                                                                                                                      ⊞υIθ


                                                                                                                      ... cast the input to integer and push it to the list.



                                                                                                                      ILυ


                                                                                                                      Cast the length of the list to string and implicitly print it.






                                                                                                                      share|improve this answer

























                                                                                                                        up vote
                                                                                                                        0
                                                                                                                        down vote














                                                                                                                        Charcoal, 19 bytes



                                                                                                                        W∨‹Lυ²¬№IΠυθ⊞υIθILυ


                                                                                                                        Try it online! Link is to verbose version of code. Explanation:



                                                                                                                        W∨‹Lυ²¬№IΠυθ⊞


                                                                                                                        Repeat until the the list length is at least 2 and its product contains the input...



                                                                                                                        ⊞υIθ


                                                                                                                        ... cast the input to integer and push it to the list.



                                                                                                                        ILυ


                                                                                                                        Cast the length of the list to string and implicitly print it.






                                                                                                                        share|improve this answer























                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote










                                                                                                                          up vote
                                                                                                                          0
                                                                                                                          down vote










                                                                                                                          Charcoal, 19 bytes



                                                                                                                          W∨‹Lυ²¬№IΠυθ⊞υIθILυ


                                                                                                                          Try it online! Link is to verbose version of code. Explanation:



                                                                                                                          W∨‹Lυ²¬№IΠυθ⊞


                                                                                                                          Repeat until the the list length is at least 2 and its product contains the input...



                                                                                                                          ⊞υIθ


                                                                                                                          ... cast the input to integer and push it to the list.



                                                                                                                          ILυ


                                                                                                                          Cast the length of the list to string and implicitly print it.






                                                                                                                          share|improve this answer













                                                                                                                          Charcoal, 19 bytes



                                                                                                                          W∨‹Lυ²¬№IΠυθ⊞υIθILυ


                                                                                                                          Try it online! Link is to verbose version of code. Explanation:



                                                                                                                          W∨‹Lυ²¬№IΠυθ⊞


                                                                                                                          Repeat until the the list length is at least 2 and its product contains the input...



                                                                                                                          ⊞υIθ


                                                                                                                          ... cast the input to integer and push it to the list.



                                                                                                                          ILυ


                                                                                                                          Cast the length of the list to string and implicitly print it.







                                                                                                                          share|improve this answer












                                                                                                                          share|improve this answer



                                                                                                                          share|improve this answer










                                                                                                                          answered Nov 28 at 20:06









                                                                                                                          Neil

                                                                                                                          78.7k744175




                                                                                                                          78.7k744175






















                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote














                                                                                                                              Python 3, 63 58 bytes





                                                                                                                              def f(n,e=2):
                                                                                                                              while str(n)not in str(n**e):e+=1
                                                                                                                              return e


                                                                                                                              Try it online!



                                                                                                                              Python2 would probably be shorter, but I like using 3. Coming up wiht a lambda is difficult, but I'm trying a few things.






                                                                                                                              share|improve this answer























                                                                                                                              • I dont know python but, isn't it shorter using lambda?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:05










                                                                                                                              • @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                                                                                                                                – Gigaflop
                                                                                                                                Nov 28 at 20:07










                                                                                                                              • Maybe some recursive function?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:10






                                                                                                                              • 2




                                                                                                                                Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                                                                                                                                – BMO
                                                                                                                                Nov 28 at 20:38










                                                                                                                              • @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                                                                                                                                – DJMcMayhem
                                                                                                                                Nov 28 at 20:44















                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote














                                                                                                                              Python 3, 63 58 bytes





                                                                                                                              def f(n,e=2):
                                                                                                                              while str(n)not in str(n**e):e+=1
                                                                                                                              return e


                                                                                                                              Try it online!



                                                                                                                              Python2 would probably be shorter, but I like using 3. Coming up wiht a lambda is difficult, but I'm trying a few things.






                                                                                                                              share|improve this answer























                                                                                                                              • I dont know python but, isn't it shorter using lambda?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:05










                                                                                                                              • @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                                                                                                                                – Gigaflop
                                                                                                                                Nov 28 at 20:07










                                                                                                                              • Maybe some recursive function?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:10






                                                                                                                              • 2




                                                                                                                                Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                                                                                                                                – BMO
                                                                                                                                Nov 28 at 20:38










                                                                                                                              • @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                                                                                                                                – DJMcMayhem
                                                                                                                                Nov 28 at 20:44













                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote










                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote










                                                                                                                              Python 3, 63 58 bytes





                                                                                                                              def f(n,e=2):
                                                                                                                              while str(n)not in str(n**e):e+=1
                                                                                                                              return e


                                                                                                                              Try it online!



                                                                                                                              Python2 would probably be shorter, but I like using 3. Coming up wiht a lambda is difficult, but I'm trying a few things.






                                                                                                                              share|improve this answer















                                                                                                                              Python 3, 63 58 bytes





                                                                                                                              def f(n,e=2):
                                                                                                                              while str(n)not in str(n**e):e+=1
                                                                                                                              return e


                                                                                                                              Try it online!



                                                                                                                              Python2 would probably be shorter, but I like using 3. Coming up wiht a lambda is difficult, but I'm trying a few things.







                                                                                                                              share|improve this answer














                                                                                                                              share|improve this answer



                                                                                                                              share|improve this answer








                                                                                                                              edited Nov 28 at 21:02

























                                                                                                                              answered Nov 28 at 20:00









                                                                                                                              Gigaflop

                                                                                                                              2216




                                                                                                                              2216












                                                                                                                              • I dont know python but, isn't it shorter using lambda?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:05










                                                                                                                              • @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                                                                                                                                – Gigaflop
                                                                                                                                Nov 28 at 20:07










                                                                                                                              • Maybe some recursive function?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:10






                                                                                                                              • 2




                                                                                                                                Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                                                                                                                                – BMO
                                                                                                                                Nov 28 at 20:38










                                                                                                                              • @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                                                                                                                                – DJMcMayhem
                                                                                                                                Nov 28 at 20:44


















                                                                                                                              • I dont know python but, isn't it shorter using lambda?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:05










                                                                                                                              • @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                                                                                                                                – Gigaflop
                                                                                                                                Nov 28 at 20:07










                                                                                                                              • Maybe some recursive function?
                                                                                                                                – Luis felipe De jesus Munoz
                                                                                                                                Nov 28 at 20:10






                                                                                                                              • 2




                                                                                                                                Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                                                                                                                                – BMO
                                                                                                                                Nov 28 at 20:38










                                                                                                                              • @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                                                                                                                                – DJMcMayhem
                                                                                                                                Nov 28 at 20:44
















                                                                                                                              I dont know python but, isn't it shorter using lambda?
                                                                                                                              – Luis felipe De jesus Munoz
                                                                                                                              Nov 28 at 20:05




                                                                                                                              I dont know python but, isn't it shorter using lambda?
                                                                                                                              – Luis felipe De jesus Munoz
                                                                                                                              Nov 28 at 20:05












                                                                                                                              @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                                                                                                                              – Gigaflop
                                                                                                                              Nov 28 at 20:07




                                                                                                                              @LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a bare while in a lambda. Maybe I can try some other ways..
                                                                                                                              – Gigaflop
                                                                                                                              Nov 28 at 20:07












                                                                                                                              Maybe some recursive function?
                                                                                                                              – Luis felipe De jesus Munoz
                                                                                                                              Nov 28 at 20:10




                                                                                                                              Maybe some recursive function?
                                                                                                                              – Luis felipe De jesus Munoz
                                                                                                                              Nov 28 at 20:10




                                                                                                                              2




                                                                                                                              2




                                                                                                                              Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                                                                                                                              – BMO
                                                                                                                              Nov 28 at 20:38




                                                                                                                              Defining e in the arguments-list (ie. def f(n,e=2)) and n**e should save some bytes, Python 2 would indeed save quite some bytes.
                                                                                                                              – BMO
                                                                                                                              Nov 28 at 20:38












                                                                                                                              @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                                                                                                                              – DJMcMayhem
                                                                                                                              Nov 28 at 20:44




                                                                                                                              @LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands like for or while do not work.
                                                                                                                              – DJMcMayhem
                                                                                                                              Nov 28 at 20:44










                                                                                                                              up vote
                                                                                                                              0
                                                                                                                              down vote














                                                                                                                              MathGolf, 10 bytes



                                                                                                                              ôkï⌠#k╧▼ï⌠


                                                                                                                              Try it online!



                                                                                                                              Explanation



                                                                                                                              This feels extremely wasteful, having to read the input explicitly twice, having to increment the loop counter twice.



                                                                                                                              ô            start block of length 6
                                                                                                                              k read integer from input
                                                                                                                              ï index of current loop, or length of last loop
                                                                                                                              ⌠ increment twice
                                                                                                                              # pop a, b : push(a**b)
                                                                                                                              k read integer from input
                                                                                                                              ╧ pop a, b, a.contains(b)
                                                                                                                              ▼ do while false with pop
                                                                                                                              ï index of current loop, or length of last loop
                                                                                                                              ⌠ increment twice





                                                                                                                              share|improve this answer

























                                                                                                                                up vote
                                                                                                                                0
                                                                                                                                down vote














                                                                                                                                MathGolf, 10 bytes



                                                                                                                                ôkï⌠#k╧▼ï⌠


                                                                                                                                Try it online!



                                                                                                                                Explanation



                                                                                                                                This feels extremely wasteful, having to read the input explicitly twice, having to increment the loop counter twice.



                                                                                                                                ô            start block of length 6
                                                                                                                                k read integer from input
                                                                                                                                ï index of current loop, or length of last loop
                                                                                                                                ⌠ increment twice
                                                                                                                                # pop a, b : push(a**b)
                                                                                                                                k read integer from input
                                                                                                                                ╧ pop a, b, a.contains(b)
                                                                                                                                ▼ do while false with pop
                                                                                                                                ï index of current loop, or length of last loop
                                                                                                                                ⌠ increment twice





                                                                                                                                share|improve this answer























                                                                                                                                  up vote
                                                                                                                                  0
                                                                                                                                  down vote










                                                                                                                                  up vote
                                                                                                                                  0
                                                                                                                                  down vote










                                                                                                                                  MathGolf, 10 bytes



                                                                                                                                  ôkï⌠#k╧▼ï⌠


                                                                                                                                  Try it online!



                                                                                                                                  Explanation



                                                                                                                                  This feels extremely wasteful, having to read the input explicitly twice, having to increment the loop counter twice.



                                                                                                                                  ô            start block of length 6
                                                                                                                                  k read integer from input
                                                                                                                                  ï index of current loop, or length of last loop
                                                                                                                                  ⌠ increment twice
                                                                                                                                  # pop a, b : push(a**b)
                                                                                                                                  k read integer from input
                                                                                                                                  ╧ pop a, b, a.contains(b)
                                                                                                                                  ▼ do while false with pop
                                                                                                                                  ï index of current loop, or length of last loop
                                                                                                                                  ⌠ increment twice





                                                                                                                                  share|improve this answer













                                                                                                                                  MathGolf, 10 bytes



                                                                                                                                  ôkï⌠#k╧▼ï⌠


                                                                                                                                  Try it online!



                                                                                                                                  Explanation



                                                                                                                                  This feels extremely wasteful, having to read the input explicitly twice, having to increment the loop counter twice.



                                                                                                                                  ô            start block of length 6
                                                                                                                                  k read integer from input
                                                                                                                                  ï index of current loop, or length of last loop
                                                                                                                                  ⌠ increment twice
                                                                                                                                  # pop a, b : push(a**b)
                                                                                                                                  k read integer from input
                                                                                                                                  ╧ pop a, b, a.contains(b)
                                                                                                                                  ▼ do while false with pop
                                                                                                                                  ï index of current loop, or length of last loop
                                                                                                                                  ⌠ increment twice






                                                                                                                                  share|improve this answer












                                                                                                                                  share|improve this answer



                                                                                                                                  share|improve this answer










                                                                                                                                  answered Nov 29 at 8:21









                                                                                                                                  maxb

                                                                                                                                  2,4581926




                                                                                                                                  2,4581926






















                                                                                                                                      up vote
                                                                                                                                      0
                                                                                                                                      down vote














                                                                                                                                      Ruby, 41 bytes





                                                                                                                                      f=->n,a=n{(a*=n).to_s=~/#{n}/?2:1+f[n,a]}


                                                                                                                                      Try it online!






                                                                                                                                      share|improve this answer

























                                                                                                                                        up vote
                                                                                                                                        0
                                                                                                                                        down vote














                                                                                                                                        Ruby, 41 bytes





                                                                                                                                        f=->n,a=n{(a*=n).to_s=~/#{n}/?2:1+f[n,a]}


                                                                                                                                        Try it online!






                                                                                                                                        share|improve this answer























                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote










                                                                                                                                          up vote
                                                                                                                                          0
                                                                                                                                          down vote










                                                                                                                                          Ruby, 41 bytes





                                                                                                                                          f=->n,a=n{(a*=n).to_s=~/#{n}/?2:1+f[n,a]}


                                                                                                                                          Try it online!






                                                                                                                                          share|improve this answer













                                                                                                                                          Ruby, 41 bytes





                                                                                                                                          f=->n,a=n{(a*=n).to_s=~/#{n}/?2:1+f[n,a]}


                                                                                                                                          Try it online!







                                                                                                                                          share|improve this answer












                                                                                                                                          share|improve this answer



                                                                                                                                          share|improve this answer










                                                                                                                                          answered Nov 29 at 12:57









                                                                                                                                          G B

                                                                                                                                          7,6461328




                                                                                                                                          7,6461328






















                                                                                                                                              up vote
                                                                                                                                              0
                                                                                                                                              down vote














                                                                                                                                              C# (.NET Core), 104 89 bytes





                                                                                                                                              a=>{int i=2;while(!(System.Numerics.BigInteger.Pow(a,i)+"").Contains(a+""))i++;return i;}


                                                                                                                                              Try it online!



                                                                                                                                              -1 byte: changed for loop to while (thanks to Skidsdev)
                                                                                                                                              -14 bytes: abused C#'s weird string handling to remove ToString() calls



                                                                                                                                              Need to use C#'s BigInteger library, as the standard numeric C# types (int, double, long, ulong, etc.) fail for some larger numbers (including 12, 15, and 17).



                                                                                                                                              Ungolfed:



                                                                                                                                              a => {
                                                                                                                                              int i = 2; // initialize i

                                                                                                                                              while( !(System.Numerics.BigInteger.Pow(a,i) + "") // n = a^i, convert to string
                                                                                                                                              .Contains(a + "")) // if n doesn't contain a
                                                                                                                                              i++; // increment i

                                                                                                                                              return i;
                                                                                                                                              }





                                                                                                                                              share|improve this answer























                                                                                                                                              • You can save 1 byte by switching to a while loop
                                                                                                                                                – Skidsdev
                                                                                                                                                Nov 29 at 13:53















                                                                                                                                              up vote
                                                                                                                                              0
                                                                                                                                              down vote














                                                                                                                                              C# (.NET Core), 104 89 bytes





                                                                                                                                              a=>{int i=2;while(!(System.Numerics.BigInteger.Pow(a,i)+"").Contains(a+""))i++;return i;}


                                                                                                                                              Try it online!



                                                                                                                                              -1 byte: changed for loop to while (thanks to Skidsdev)
                                                                                                                                              -14 bytes: abused C#'s weird string handling to remove ToString() calls



                                                                                                                                              Need to use C#'s BigInteger library, as the standard numeric C# types (int, double, long, ulong, etc.) fail for some larger numbers (including 12, 15, and 17).



                                                                                                                                              Ungolfed:



                                                                                                                                              a => {
                                                                                                                                              int i = 2; // initialize i

                                                                                                                                              while( !(System.Numerics.BigInteger.Pow(a,i) + "") // n = a^i, convert to string
                                                                                                                                              .Contains(a + "")) // if n doesn't contain a
                                                                                                                                              i++; // increment i

                                                                                                                                              return i;
                                                                                                                                              }





                                                                                                                                              share|improve this answer























                                                                                                                                              • You can save 1 byte by switching to a while loop
                                                                                                                                                – Skidsdev
                                                                                                                                                Nov 29 at 13:53













                                                                                                                                              up vote
                                                                                                                                              0
                                                                                                                                              down vote










                                                                                                                                              up vote
                                                                                                                                              0
                                                                                                                                              down vote










                                                                                                                                              C# (.NET Core), 104 89 bytes





                                                                                                                                              a=>{int i=2;while(!(System.Numerics.BigInteger.Pow(a,i)+"").Contains(a+""))i++;return i;}


                                                                                                                                              Try it online!



                                                                                                                                              -1 byte: changed for loop to while (thanks to Skidsdev)
                                                                                                                                              -14 bytes: abused C#'s weird string handling to remove ToString() calls



                                                                                                                                              Need to use C#'s BigInteger library, as the standard numeric C# types (int, double, long, ulong, etc.) fail for some larger numbers (including 12, 15, and 17).



                                                                                                                                              Ungolfed:



                                                                                                                                              a => {
                                                                                                                                              int i = 2; // initialize i

                                                                                                                                              while( !(System.Numerics.BigInteger.Pow(a,i) + "") // n = a^i, convert to string
                                                                                                                                              .Contains(a + "")) // if n doesn't contain a
                                                                                                                                              i++; // increment i

                                                                                                                                              return i;
                                                                                                                                              }





                                                                                                                                              share|improve this answer















                                                                                                                                              C# (.NET Core), 104 89 bytes





                                                                                                                                              a=>{int i=2;while(!(System.Numerics.BigInteger.Pow(a,i)+"").Contains(a+""))i++;return i;}


                                                                                                                                              Try it online!



                                                                                                                                              -1 byte: changed for loop to while (thanks to Skidsdev)
                                                                                                                                              -14 bytes: abused C#'s weird string handling to remove ToString() calls



                                                                                                                                              Need to use C#'s BigInteger library, as the standard numeric C# types (int, double, long, ulong, etc.) fail for some larger numbers (including 12, 15, and 17).



                                                                                                                                              Ungolfed:



                                                                                                                                              a => {
                                                                                                                                              int i = 2; // initialize i

                                                                                                                                              while( !(System.Numerics.BigInteger.Pow(a,i) + "") // n = a^i, convert to string
                                                                                                                                              .Contains(a + "")) // if n doesn't contain a
                                                                                                                                              i++; // increment i

                                                                                                                                              return i;
                                                                                                                                              }






                                                                                                                                              share|improve this answer














                                                                                                                                              share|improve this answer



                                                                                                                                              share|improve this answer








                                                                                                                                              edited Nov 29 at 14:46

























                                                                                                                                              answered Nov 28 at 21:22









                                                                                                                                              Meerkat

                                                                                                                                              3318




                                                                                                                                              3318












                                                                                                                                              • You can save 1 byte by switching to a while loop
                                                                                                                                                – Skidsdev
                                                                                                                                                Nov 29 at 13:53


















                                                                                                                                              • You can save 1 byte by switching to a while loop
                                                                                                                                                – Skidsdev
                                                                                                                                                Nov 29 at 13:53
















                                                                                                                                              You can save 1 byte by switching to a while loop
                                                                                                                                              – Skidsdev
                                                                                                                                              Nov 29 at 13:53




                                                                                                                                              You can save 1 byte by switching to a while loop
                                                                                                                                              – Skidsdev
                                                                                                                                              Nov 29 at 13:53










                                                                                                                                              up vote
                                                                                                                                              0
                                                                                                                                              down vote














                                                                                                                                              Python 2, 47 bytes





                                                                                                                                              i,e=input(),2
                                                                                                                                              while`i`not in`i**e`:e+=1
                                                                                                                                              print e


                                                                                                                                              Try it online!



                                                                                                                                              Inspired by @Gigaflop's solution.






                                                                                                                                              share|improve this answer

























                                                                                                                                                up vote
                                                                                                                                                0
                                                                                                                                                down vote














                                                                                                                                                Python 2, 47 bytes





                                                                                                                                                i,e=input(),2
                                                                                                                                                while`i`not in`i**e`:e+=1
                                                                                                                                                print e


                                                                                                                                                Try it online!



                                                                                                                                                Inspired by @Gigaflop's solution.






                                                                                                                                                share|improve this answer























                                                                                                                                                  up vote
                                                                                                                                                  0
                                                                                                                                                  down vote










                                                                                                                                                  up vote
                                                                                                                                                  0
                                                                                                                                                  down vote










                                                                                                                                                  Python 2, 47 bytes





                                                                                                                                                  i,e=input(),2
                                                                                                                                                  while`i`not in`i**e`:e+=1
                                                                                                                                                  print e


                                                                                                                                                  Try it online!



                                                                                                                                                  Inspired by @Gigaflop's solution.






                                                                                                                                                  share|improve this answer













                                                                                                                                                  Python 2, 47 bytes





                                                                                                                                                  i,e=input(),2
                                                                                                                                                  while`i`not in`i**e`:e+=1
                                                                                                                                                  print e


                                                                                                                                                  Try it online!



                                                                                                                                                  Inspired by @Gigaflop's solution.







                                                                                                                                                  share|improve this answer












                                                                                                                                                  share|improve this answer



                                                                                                                                                  share|improve this answer










                                                                                                                                                  answered Nov 29 at 15:39









                                                                                                                                                  glietz

                                                                                                                                                  816




                                                                                                                                                  816






















                                                                                                                                                      up vote
                                                                                                                                                      0
                                                                                                                                                      down vote














                                                                                                                                                      Tcl, 69 81 bytes



                                                                                                                                                      proc S n {incr i
                                                                                                                                                      while {![regexp $n [expr $n**[incr i]]]} {}
                                                                                                                                                      puts $i}


                                                                                                                                                      Try it online!






                                                                                                                                                      share|improve this answer























                                                                                                                                                      • Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                                                                                                                                        – sergiol
                                                                                                                                                        Nov 29 at 23:22















                                                                                                                                                      up vote
                                                                                                                                                      0
                                                                                                                                                      down vote














                                                                                                                                                      Tcl, 69 81 bytes



                                                                                                                                                      proc S n {incr i
                                                                                                                                                      while {![regexp $n [expr $n**[incr i]]]} {}
                                                                                                                                                      puts $i}


                                                                                                                                                      Try it online!






                                                                                                                                                      share|improve this answer























                                                                                                                                                      • Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                                                                                                                                        – sergiol
                                                                                                                                                        Nov 29 at 23:22













                                                                                                                                                      up vote
                                                                                                                                                      0
                                                                                                                                                      down vote










                                                                                                                                                      up vote
                                                                                                                                                      0
                                                                                                                                                      down vote










                                                                                                                                                      Tcl, 69 81 bytes



                                                                                                                                                      proc S n {incr i
                                                                                                                                                      while {![regexp $n [expr $n**[incr i]]]} {}
                                                                                                                                                      puts $i}


                                                                                                                                                      Try it online!






                                                                                                                                                      share|improve this answer















                                                                                                                                                      Tcl, 69 81 bytes



                                                                                                                                                      proc S n {incr i
                                                                                                                                                      while {![regexp $n [expr $n**[incr i]]]} {}
                                                                                                                                                      puts $i}


                                                                                                                                                      Try it online!







                                                                                                                                                      share|improve this answer














                                                                                                                                                      share|improve this answer



                                                                                                                                                      share|improve this answer








                                                                                                                                                      edited Nov 29 at 23:17

























                                                                                                                                                      answered Nov 29 at 23:01









                                                                                                                                                      sergiol

                                                                                                                                                      2,3121925




                                                                                                                                                      2,3121925












                                                                                                                                                      • Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                                                                                                                                        – sergiol
                                                                                                                                                        Nov 29 at 23:22


















                                                                                                                                                      • Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                                                                                                                                        – sergiol
                                                                                                                                                        Nov 29 at 23:22
















                                                                                                                                                      Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                                                                                                                                      – sergiol
                                                                                                                                                      Nov 29 at 23:22




                                                                                                                                                      Same byte count: tio.run/##DY7LaoNQFEXn6yt2IKOMzlGPj@/…
                                                                                                                                                      – sergiol
                                                                                                                                                      Nov 29 at 23:22










                                                                                                                                                      up vote
                                                                                                                                                      0
                                                                                                                                                      down vote













                                                                                                                                                      PowerShell(V3+), 67 bytes



                                                                                                                                                      function f{param($n)$i=1;do{}until([math]::pow($n,++$i)-match$n)$i}





                                                                                                                                                      share|improve this answer

























                                                                                                                                                        up vote
                                                                                                                                                        0
                                                                                                                                                        down vote













                                                                                                                                                        PowerShell(V3+), 67 bytes



                                                                                                                                                        function f{param($n)$i=1;do{}until([math]::pow($n,++$i)-match$n)$i}





                                                                                                                                                        share|improve this answer























                                                                                                                                                          up vote
                                                                                                                                                          0
                                                                                                                                                          down vote










                                                                                                                                                          up vote
                                                                                                                                                          0
                                                                                                                                                          down vote









                                                                                                                                                          PowerShell(V3+), 67 bytes



                                                                                                                                                          function f{param($n)$i=1;do{}until([math]::pow($n,++$i)-match$n)$i}





                                                                                                                                                          share|improve this answer












                                                                                                                                                          PowerShell(V3+), 67 bytes



                                                                                                                                                          function f{param($n)$i=1;do{}until([math]::pow($n,++$i)-match$n)$i}






                                                                                                                                                          share|improve this answer












                                                                                                                                                          share|improve this answer



                                                                                                                                                          share|improve this answer










                                                                                                                                                          answered Nov 30 at 0:24









                                                                                                                                                          jyao

                                                                                                                                                          1314




                                                                                                                                                          1314






















                                                                                                                                                              up vote
                                                                                                                                                              0
                                                                                                                                                              down vote













                                                                                                                                                              Common Lisp, 78 bytes



                                                                                                                                                              (lambda(n)(do((e 2(1+ e)))((search(format()"~d"n)(format()"~d"(expt n e)))e)))


                                                                                                                                                              Try it online!






                                                                                                                                                              share|improve this answer

























                                                                                                                                                                up vote
                                                                                                                                                                0
                                                                                                                                                                down vote













                                                                                                                                                                Common Lisp, 78 bytes



                                                                                                                                                                (lambda(n)(do((e 2(1+ e)))((search(format()"~d"n)(format()"~d"(expt n e)))e)))


                                                                                                                                                                Try it online!






                                                                                                                                                                share|improve this answer























                                                                                                                                                                  up vote
                                                                                                                                                                  0
                                                                                                                                                                  down vote










                                                                                                                                                                  up vote
                                                                                                                                                                  0
                                                                                                                                                                  down vote









                                                                                                                                                                  Common Lisp, 78 bytes



                                                                                                                                                                  (lambda(n)(do((e 2(1+ e)))((search(format()"~d"n)(format()"~d"(expt n e)))e)))


                                                                                                                                                                  Try it online!






                                                                                                                                                                  share|improve this answer












                                                                                                                                                                  Common Lisp, 78 bytes



                                                                                                                                                                  (lambda(n)(do((e 2(1+ e)))((search(format()"~d"n)(format()"~d"(expt n e)))e)))


                                                                                                                                                                  Try it online!







                                                                                                                                                                  share|improve this answer












                                                                                                                                                                  share|improve this answer



                                                                                                                                                                  share|improve this answer










                                                                                                                                                                  answered Nov 30 at 17:25









                                                                                                                                                                  Renzo

                                                                                                                                                                  1,630516




                                                                                                                                                                  1,630516






















                                                                                                                                                                      up vote
                                                                                                                                                                      0
                                                                                                                                                                      down vote














                                                                                                                                                                      J, 26 bytes



                                                                                                                                                                      2>:@]^:(0=[+/@E.&":^)^:_~]


                                                                                                                                                                      Try it online!



                                                                                                                                                                      NOTE: I've changed the final ] to x: in the TIO, to make the tests pass for larger integers.






                                                                                                                                                                      share|improve this answer

























                                                                                                                                                                        up vote
                                                                                                                                                                        0
                                                                                                                                                                        down vote














                                                                                                                                                                        J, 26 bytes



                                                                                                                                                                        2>:@]^:(0=[+/@E.&":^)^:_~]


                                                                                                                                                                        Try it online!



                                                                                                                                                                        NOTE: I've changed the final ] to x: in the TIO, to make the tests pass for larger integers.






                                                                                                                                                                        share|improve this answer























                                                                                                                                                                          up vote
                                                                                                                                                                          0
                                                                                                                                                                          down vote










                                                                                                                                                                          up vote
                                                                                                                                                                          0
                                                                                                                                                                          down vote










                                                                                                                                                                          J, 26 bytes



                                                                                                                                                                          2>:@]^:(0=[+/@E.&":^)^:_~]


                                                                                                                                                                          Try it online!



                                                                                                                                                                          NOTE: I've changed the final ] to x: in the TIO, to make the tests pass for larger integers.






                                                                                                                                                                          share|improve this answer













                                                                                                                                                                          J, 26 bytes



                                                                                                                                                                          2>:@]^:(0=[+/@E.&":^)^:_~]


                                                                                                                                                                          Try it online!



                                                                                                                                                                          NOTE: I've changed the final ] to x: in the TIO, to make the tests pass for larger integers.







                                                                                                                                                                          share|improve this answer












                                                                                                                                                                          share|improve this answer



                                                                                                                                                                          share|improve this answer










                                                                                                                                                                          answered Dec 1 at 1:02









                                                                                                                                                                          Jonah

                                                                                                                                                                          2,011816




                                                                                                                                                                          2,011816






















                                                                                                                                                                              up vote
                                                                                                                                                                              0
                                                                                                                                                                              down vote













                                                                                                                                                                              Oracle SQL, 68 bytes



                                                                                                                                                                              select max(level)+1 from dual,t connect by instr(power(x,level),x)=0


                                                                                                                                                                              There is an assumption that source number is stored in a table t(x), e.g.



                                                                                                                                                                              with t as (select 95 x from dual)


                                                                                                                                                                              Test in SQL*Plus



                                                                                                                                                                              SQL> with t as (select 95 x from dual)
                                                                                                                                                                              2 select max(level)+1 from dual,t connect by instr(power(x,level),x)=0
                                                                                                                                                                              3 /

                                                                                                                                                                              MAX(LEVEL)+1
                                                                                                                                                                              ------------
                                                                                                                                                                              13





                                                                                                                                                                              share|improve this answer

























                                                                                                                                                                                up vote
                                                                                                                                                                                0
                                                                                                                                                                                down vote













                                                                                                                                                                                Oracle SQL, 68 bytes



                                                                                                                                                                                select max(level)+1 from dual,t connect by instr(power(x,level),x)=0


                                                                                                                                                                                There is an assumption that source number is stored in a table t(x), e.g.



                                                                                                                                                                                with t as (select 95 x from dual)


                                                                                                                                                                                Test in SQL*Plus



                                                                                                                                                                                SQL> with t as (select 95 x from dual)
                                                                                                                                                                                2 select max(level)+1 from dual,t connect by instr(power(x,level),x)=0
                                                                                                                                                                                3 /

                                                                                                                                                                                MAX(LEVEL)+1
                                                                                                                                                                                ------------
                                                                                                                                                                                13





                                                                                                                                                                                share|improve this answer























                                                                                                                                                                                  up vote
                                                                                                                                                                                  0
                                                                                                                                                                                  down vote










                                                                                                                                                                                  up vote
                                                                                                                                                                                  0
                                                                                                                                                                                  down vote









                                                                                                                                                                                  Oracle SQL, 68 bytes



                                                                                                                                                                                  select max(level)+1 from dual,t connect by instr(power(x,level),x)=0


                                                                                                                                                                                  There is an assumption that source number is stored in a table t(x), e.g.



                                                                                                                                                                                  with t as (select 95 x from dual)


                                                                                                                                                                                  Test in SQL*Plus



                                                                                                                                                                                  SQL> with t as (select 95 x from dual)
                                                                                                                                                                                  2 select max(level)+1 from dual,t connect by instr(power(x,level),x)=0
                                                                                                                                                                                  3 /

                                                                                                                                                                                  MAX(LEVEL)+1
                                                                                                                                                                                  ------------
                                                                                                                                                                                  13





                                                                                                                                                                                  share|improve this answer












                                                                                                                                                                                  Oracle SQL, 68 bytes



                                                                                                                                                                                  select max(level)+1 from dual,t connect by instr(power(x,level),x)=0


                                                                                                                                                                                  There is an assumption that source number is stored in a table t(x), e.g.



                                                                                                                                                                                  with t as (select 95 x from dual)


                                                                                                                                                                                  Test in SQL*Plus



                                                                                                                                                                                  SQL> with t as (select 95 x from dual)
                                                                                                                                                                                  2 select max(level)+1 from dual,t connect by instr(power(x,level),x)=0
                                                                                                                                                                                  3 /

                                                                                                                                                                                  MAX(LEVEL)+1
                                                                                                                                                                                  ------------
                                                                                                                                                                                  13






                                                                                                                                                                                  share|improve this answer












                                                                                                                                                                                  share|improve this answer



                                                                                                                                                                                  share|improve this answer










                                                                                                                                                                                  answered Dec 3 at 13:20









                                                                                                                                                                                  Dr Y Wit

                                                                                                                                                                                  1614




                                                                                                                                                                                  1614






























                                                                                                                                                                                      draft saved

                                                                                                                                                                                      draft discarded




















































                                                                                                                                                                                      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.




                                                                                                                                                                                      draft saved


                                                                                                                                                                                      draft discarded














                                                                                                                                                                                      StackExchange.ready(
                                                                                                                                                                                      function () {
                                                                                                                                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176734%2fself-contained-powers%23new-answer', 'question_page');
                                                                                                                                                                                      }
                                                                                                                                                                                      );

                                                                                                                                                                                      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







                                                                                                                                                                                      Popular posts from this blog

                                                                                                                                                                                      Ellipse (mathématiques)

                                                                                                                                                                                      Quarter-circle Tiles

                                                                                                                                                                                      Mont Emei