Self-contained powers
up vote
6
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
nwill always be an integer greater than0
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
add a comment |
up vote
6
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
nwill always be an integer greater than0
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
Related
– Skidsdev
8 hours ago
A045537
– Shaggy
6 hours ago
add a comment |
up vote
6
down vote
favorite
up vote
6
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
nwill always be an integer greater than0
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
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
nwill always be an integer greater than0
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
code-golf number
asked 8 hours ago
Skidsdev
6,1242868
6,1242868
Related
– Skidsdev
8 hours ago
A045537
– Shaggy
6 hours ago
add a comment |
Related
– Skidsdev
8 hours ago
A045537
– Shaggy
6 hours ago
Related
– Skidsdev
8 hours ago
Related
– Skidsdev
8 hours ago
A045537
– Shaggy
6 hours ago
A045537
– Shaggy
6 hours ago
add a comment |
15 Answers
15
active
oldest
votes
up vote
3
down vote
Perl 6, 31 bytes
{$^a;first {$a**$_~~/$a/},2..*}
Try it online!
add a comment |
up vote
2
down vote
R, 69 bytes
function(n,i=2){while(!grepl(?n, ?n^i))i=i+1;cat(i)}
`?`=as.character
Anonymous function.
Try it online!
61 bytes -- you had an extra space inn, ?n^iandpasteconverts tocharacterby default :-)
– Giuseppe
6 hours ago
56 bytes -- returningishould be sufficient.
– Giuseppe
6 hours ago
add a comment |
up vote
2
down vote
JavaScript (ES6), 41 40 bytes
Saved 1 byte thanks to @Shaggy
Takes input as a BigInt literal.
n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)
Try it online!
1
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
@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 bytecountn=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
– Luis felipe De jesus Munoz
6 hours ago
1
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
add a comment |
up vote
2
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!
1
Returning y is shorter
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
add a comment |
up vote
2
down vote
APL (Dyalog Unicode), 25 23 17 bytes
-2 bytes thanks to @Erik the Outgolfer
-6 bytes thanks to @ngn
⊢⍟×⍣(∨/(⍕÷)⍷∘⍕⊣)⍨
My mind is blown.
Try it online!
APL (Dyalog Unicode), 25 bytes
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
This function is composed with the left argument 2.
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
∨/ At any point
(⍕⍵) can the string representation of ⍵
⍷ be found in
⍕⍵*⍺ the string representation of ⍵ to the power of ⍺? (starting at 2)
:⍺ If so, return ⍺
(⍺+1)∇⍵ Else, return the result of the function with ⍺+1
Try it online!
This fails for 17 because it it finds17in 17^14=1.6837782655940093E17, but idk to what precision answers should support
– Cows quack
7 hours ago
@Cowsquack I just have to arbitrarily adjust⎕PPI guess
– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
19 bytes
– ngn
5 hours ago
|
show 3 more comments
up vote
1
down vote
Pyth, 9 bytes
f}`Q`^QT2
Try it online!
add a comment |
up vote
1
down vote
Jelly, 7 bytes
2ẇ*¥@1#
Try it online!
add a comment |
up vote
1
down vote
05AB1E, 7 bytes
∞>.Δm¹å
Try it online!
add a comment |
up vote
0
down vote
Ruby, 37 bytes
->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}
Try it online!
add a comment |
up vote
0
down vote
Japt, 10 bytes
@pX søU}a2
Try it
add a comment |
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!
add a comment |
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.
add a comment |
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.
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
@LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a barewhilein a lambda. Maybe I can try some other ways..
– Gigaflop
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
2
Definingein the arguments-list (ie.def f(n,e=2)) andn**eshould save some bytes, Python 2 would indeed save quite some bytes.
– BMO
5 hours ago
@LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands likefororwhiledo not work.
– DJMcMayhem♦
5 hours ago
|
show 1 more comment
up vote
0
down vote
C# (.NET Core), 104 bytes
a=>{for(int i=2;;i++)if(System.Numerics.BigInteger.Pow(a,i).ToString().Contains(a.ToString()))return i;}
Try it online!
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 => {
for(int i = 2; ; i++) // starting from 2
if( System.Numerics.BigInteger.Pow(a,i) // n = a^i
.ToString().Contains(a.ToString()) ) // if n contains a
return i; // return i
}
add a comment |
up vote
0
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!
add a comment |
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Perl 6, 31 bytes
{$^a;first {$a**$_~~/$a/},2..*}
Try it online!
add a comment |
up vote
3
down vote
Perl 6, 31 bytes
{$^a;first {$a**$_~~/$a/},2..*}
Try it online!
add a comment |
up vote
3
down vote
up vote
3
down vote
Perl 6, 31 bytes
{$^a;first {$a**$_~~/$a/},2..*}
Try it online!
Perl 6, 31 bytes
{$^a;first {$a**$_~~/$a/},2..*}
Try it online!
answered 7 hours ago
Sean
3,17636
3,17636
add a comment |
add a comment |
up vote
2
down vote
R, 69 bytes
function(n,i=2){while(!grepl(?n, ?n^i))i=i+1;cat(i)}
`?`=as.character
Anonymous function.
Try it online!
61 bytes -- you had an extra space inn, ?n^iandpasteconverts tocharacterby default :-)
– Giuseppe
6 hours ago
56 bytes -- returningishould be sufficient.
– Giuseppe
6 hours ago
add a comment |
up vote
2
down vote
R, 69 bytes
function(n,i=2){while(!grepl(?n, ?n^i))i=i+1;cat(i)}
`?`=as.character
Anonymous function.
Try it online!
61 bytes -- you had an extra space inn, ?n^iandpasteconverts tocharacterby default :-)
– Giuseppe
6 hours ago
56 bytes -- returningishould be sufficient.
– Giuseppe
6 hours ago
add a comment |
up vote
2
down vote
up vote
2
down vote
R, 69 bytes
function(n,i=2){while(!grepl(?n, ?n^i))i=i+1;cat(i)}
`?`=as.character
Anonymous function.
Try it online!
R, 69 bytes
function(n,i=2){while(!grepl(?n, ?n^i))i=i+1;cat(i)}
`?`=as.character
Anonymous function.
Try it online!
answered 7 hours ago
BLT
856412
856412
61 bytes -- you had an extra space inn, ?n^iandpasteconverts tocharacterby default :-)
– Giuseppe
6 hours ago
56 bytes -- returningishould be sufficient.
– Giuseppe
6 hours ago
add a comment |
61 bytes -- you had an extra space inn, ?n^iandpasteconverts tocharacterby default :-)
– Giuseppe
6 hours ago
56 bytes -- returningishould be sufficient.
– Giuseppe
6 hours ago
61 bytes -- you had an extra space in
n, ?n^i and paste converts to character by default :-)– Giuseppe
6 hours ago
61 bytes -- you had an extra space in
n, ?n^i and paste converts to character by default :-)– Giuseppe
6 hours ago
56 bytes -- returning
i should be sufficient.– Giuseppe
6 hours ago
56 bytes -- returning
i should be sufficient.– Giuseppe
6 hours ago
add a comment |
up vote
2
down vote
JavaScript (ES6), 41 40 bytes
Saved 1 byte thanks to @Shaggy
Takes input as a BigInt literal.
n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)
Try it online!
1
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
@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 bytecountn=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
– Luis felipe De jesus Munoz
6 hours ago
1
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
add a comment |
up vote
2
down vote
JavaScript (ES6), 41 40 bytes
Saved 1 byte thanks to @Shaggy
Takes input as a BigInt literal.
n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)
Try it online!
1
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
@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 bytecountn=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
– Luis felipe De jesus Munoz
6 hours ago
1
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
add a comment |
up vote
2
down vote
up vote
2
down vote
JavaScript (ES6), 41 40 bytes
Saved 1 byte thanks to @Shaggy
Takes input as a BigInt literal.
n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)
Try it online!
JavaScript (ES6), 41 40 bytes
Saved 1 byte thanks to @Shaggy
Takes input as a BigInt literal.
n=>(g=x=>`${x*=n}`.match(n)?2:-~g(x))(n)
Try it online!
edited 6 hours ago
answered 8 hours ago
Arnauld
70.1k686295
70.1k686295
1
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
@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 bytecountn=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
– Luis felipe De jesus Munoz
6 hours ago
1
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
add a comment |
1
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
@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 bytecountn=>(g=x=>${x*=n}.match(n)?2n:-~g(x))(n)
– Luis felipe De jesus Munoz
6 hours ago
1
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
1
1
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
Ended up with a solution very similar to yours for 40 bytes
– Shaggy
6 hours ago
@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
6 hours ago
@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
6 hours ago
1
1
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
@LuisfelipeDejesusMunoz, generally we don't need to worry about precision issues but it will work with BigInts too.
– Shaggy
6 hours ago
add a comment |
up vote
2
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!
1
Returning y is shorter
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
add a comment |
up vote
2
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!
1
Returning y is shorter
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
add a comment |
up vote
2
down vote
up vote
2
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!
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!
edited 4 hours ago
answered 5 hours ago
BMO
10.7k21880
10.7k21880
1
Returning y is shorter
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
add a comment |
1
Returning y is shorter
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
1
1
Returning y is shorter
– Ørjan Johansen
4 hours ago
Returning y is shorter
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
@ØrjanJohansen: Weird, I thought I tried that, not exactly sure what I missed. Thanks a lot!
– BMO
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
I had to swap the multiplication to avoid a space, maybe that was it?
– Ørjan Johansen
4 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
@ØrjanJohansen: Probably that was it, yeah.
– BMO
2 hours ago
add a comment |
up vote
2
down vote
APL (Dyalog Unicode), 25 23 17 bytes
-2 bytes thanks to @Erik the Outgolfer
-6 bytes thanks to @ngn
⊢⍟×⍣(∨/(⍕÷)⍷∘⍕⊣)⍨
My mind is blown.
Try it online!
APL (Dyalog Unicode), 25 bytes
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
This function is composed with the left argument 2.
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
∨/ At any point
(⍕⍵) can the string representation of ⍵
⍷ be found in
⍕⍵*⍺ the string representation of ⍵ to the power of ⍺? (starting at 2)
:⍺ If so, return ⍺
(⍺+1)∇⍵ Else, return the result of the function with ⍺+1
Try it online!
This fails for 17 because it it finds17in 17^14=1.6837782655940093E17, but idk to what precision answers should support
– Cows quack
7 hours ago
@Cowsquack I just have to arbitrarily adjust⎕PPI guess
– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
19 bytes
– ngn
5 hours ago
|
show 3 more comments
up vote
2
down vote
APL (Dyalog Unicode), 25 23 17 bytes
-2 bytes thanks to @Erik the Outgolfer
-6 bytes thanks to @ngn
⊢⍟×⍣(∨/(⍕÷)⍷∘⍕⊣)⍨
My mind is blown.
Try it online!
APL (Dyalog Unicode), 25 bytes
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
This function is composed with the left argument 2.
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
∨/ At any point
(⍕⍵) can the string representation of ⍵
⍷ be found in
⍕⍵*⍺ the string representation of ⍵ to the power of ⍺? (starting at 2)
:⍺ If so, return ⍺
(⍺+1)∇⍵ Else, return the result of the function with ⍺+1
Try it online!
This fails for 17 because it it finds17in 17^14=1.6837782655940093E17, but idk to what precision answers should support
– Cows quack
7 hours ago
@Cowsquack I just have to arbitrarily adjust⎕PPI guess
– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
19 bytes
– ngn
5 hours ago
|
show 3 more comments
up vote
2
down vote
up vote
2
down vote
APL (Dyalog Unicode), 25 23 17 bytes
-2 bytes thanks to @Erik the Outgolfer
-6 bytes thanks to @ngn
⊢⍟×⍣(∨/(⍕÷)⍷∘⍕⊣)⍨
My mind is blown.
Try it online!
APL (Dyalog Unicode), 25 bytes
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
This function is composed with the left argument 2.
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
∨/ At any point
(⍕⍵) can the string representation of ⍵
⍷ be found in
⍕⍵*⍺ the string representation of ⍵ to the power of ⍺? (starting at 2)
:⍺ If so, return ⍺
(⍺+1)∇⍵ Else, return the result of the function with ⍺+1
Try it online!
APL (Dyalog Unicode), 25 23 17 bytes
-2 bytes thanks to @Erik the Outgolfer
-6 bytes thanks to @ngn
⊢⍟×⍣(∨/(⍕÷)⍷∘⍕⊣)⍨
My mind is blown.
Try it online!
APL (Dyalog Unicode), 25 bytes
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
This function is composed with the left argument 2.
2∘{∨/(⍕⍵)⍷⍕⍵*⍺:⍺⋄(⍺+1)∇⍵}
∨/ At any point
(⍕⍵) can the string representation of ⍵
⍷ be found in
⍕⍵*⍺ the string representation of ⍵ to the power of ⍺? (starting at 2)
:⍺ If so, return ⍺
(⍺+1)∇⍵ Else, return the result of the function with ⍺+1
Try it online!
edited 48 mins ago
answered 7 hours ago
Quintec
1,215518
1,215518
This fails for 17 because it it finds17in 17^14=1.6837782655940093E17, but idk to what precision answers should support
– Cows quack
7 hours ago
@Cowsquack I just have to arbitrarily adjust⎕PPI guess
– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
19 bytes
– ngn
5 hours ago
|
show 3 more comments
This fails for 17 because it it finds17in 17^14=1.6837782655940093E17, but idk to what precision answers should support
– Cows quack
7 hours ago
@Cowsquack I just have to arbitrarily adjust⎕PPI guess
– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
19 bytes
– ngn
5 hours ago
This fails for 17 because it it finds
17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support– Cows quack
7 hours ago
This fails for 17 because it it finds
17 in 17^14=1.6837782655940093E17, but idk to what precision answers should support– Cows quack
7 hours ago
@Cowsquack I just have to arbitrarily adjust
⎕PP I guess– Quintec
7 hours ago
@Cowsquack I just have to arbitrarily adjust
⎕PP I guess– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
Oh wait that won't even work
– Quintec
7 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
23 bytes.
– Erik the Outgolfer
5 hours ago
19 bytes
– ngn
5 hours ago
19 bytes
– ngn
5 hours ago
|
show 3 more comments
up vote
1
down vote
Pyth, 9 bytes
f}`Q`^QT2
Try it online!
add a comment |
up vote
1
down vote
Pyth, 9 bytes
f}`Q`^QT2
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
Pyth, 9 bytes
f}`Q`^QT2
Try it online!
Pyth, 9 bytes
f}`Q`^QT2
Try it online!
answered 7 hours ago
lirtosiast
15.6k436105
15.6k436105
add a comment |
add a comment |
up vote
1
down vote
Jelly, 7 bytes
2ẇ*¥@1#
Try it online!
add a comment |
up vote
1
down vote
Jelly, 7 bytes
2ẇ*¥@1#
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
Jelly, 7 bytes
2ẇ*¥@1#
Try it online!
Jelly, 7 bytes
2ẇ*¥@1#
Try it online!
answered 6 hours ago
Erik the Outgolfer
30.8k429102
30.8k429102
add a comment |
add a comment |
up vote
1
down vote
05AB1E, 7 bytes
∞>.Δm¹å
Try it online!
add a comment |
up vote
1
down vote
05AB1E, 7 bytes
∞>.Δm¹å
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
05AB1E, 7 bytes
∞>.Δm¹å
Try it online!
05AB1E, 7 bytes
∞>.Δm¹å
Try it online!
answered 4 hours ago
Cowabunghole
1,010418
1,010418
add a comment |
add a comment |
up vote
0
down vote
Ruby, 37 bytes
->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}
Try it online!
add a comment |
up vote
0
down vote
Ruby, 37 bytes
->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}
Try it online!
add a comment |
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!
Ruby, 37 bytes
->n,i=2{i+=1until/#{n}/=~"#{n**i}";i}
Try it online!
answered 7 hours ago
Kirill L.
3,2761118
3,2761118
add a comment |
add a comment |
up vote
0
down vote
Japt, 10 bytes
@pX søU}a2
Try it
add a comment |
up vote
0
down vote
Japt, 10 bytes
@pX søU}a2
Try it
add a comment |
up vote
0
down vote
up vote
0
down vote
Japt, 10 bytes
@pX søU}a2
Try it
Japt, 10 bytes
@pX søU}a2
Try it
answered 7 hours ago
Shaggy
18.3k21663
18.3k21663
add a comment |
add a comment |
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!
add a comment |
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!
add a comment |
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!
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!
edited 6 hours ago
Shaggy
18.3k21663
18.3k21663
answered 8 hours ago
Luis felipe De jesus Munoz
4,01921254
4,01921254
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 6 hours ago
Neil
78.3k744175
78.3k744175
add a comment |
add a comment |
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.
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
@LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a barewhilein a lambda. Maybe I can try some other ways..
– Gigaflop
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
2
Definingein the arguments-list (ie.def f(n,e=2)) andn**eshould save some bytes, Python 2 would indeed save quite some bytes.
– BMO
5 hours ago
@LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands likefororwhiledo not work.
– DJMcMayhem♦
5 hours ago
|
show 1 more comment
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.
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
@LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a barewhilein a lambda. Maybe I can try some other ways..
– Gigaflop
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
2
Definingein the arguments-list (ie.def f(n,e=2)) andn**eshould save some bytes, Python 2 would indeed save quite some bytes.
– BMO
5 hours ago
@LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands likefororwhiledo not work.
– DJMcMayhem♦
5 hours ago
|
show 1 more comment
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.
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.
edited 5 hours ago
answered 6 hours ago
Gigaflop
2116
2116
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
@LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a barewhilein a lambda. Maybe I can try some other ways..
– Gigaflop
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
2
Definingein the arguments-list (ie.def f(n,e=2)) andn**eshould save some bytes, Python 2 would indeed save quite some bytes.
– BMO
5 hours ago
@LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands likefororwhiledo not work.
– DJMcMayhem♦
5 hours ago
|
show 1 more comment
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
@LuisfelipeDejesusMunoz I started off trying to do that, but IDLE complained about having a barewhilein a lambda. Maybe I can try some other ways..
– Gigaflop
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
2
Definingein the arguments-list (ie.def f(n,e=2)) andn**eshould save some bytes, Python 2 would indeed save quite some bytes.
– BMO
5 hours ago
@LuisfelipeDejesusMunoz Lambdas are not like functions. The right hand side of a lambda has to be a single expression, and flow-control commands likefororwhiledo not work.
– DJMcMayhem♦
5 hours ago
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
I dont know python but, isn't it shorter using lambda?
– Luis felipe De jesus Munoz
6 hours ago
@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
6 hours ago
@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
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
Maybe some recursive function?
– Luis felipe De jesus Munoz
6 hours ago
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
5 hours ago
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
5 hours ago
@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♦
5 hours ago
@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♦
5 hours ago
|
show 1 more comment
up vote
0
down vote
C# (.NET Core), 104 bytes
a=>{for(int i=2;;i++)if(System.Numerics.BigInteger.Pow(a,i).ToString().Contains(a.ToString()))return i;}
Try it online!
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 => {
for(int i = 2; ; i++) // starting from 2
if( System.Numerics.BigInteger.Pow(a,i) // n = a^i
.ToString().Contains(a.ToString()) ) // if n contains a
return i; // return i
}
add a comment |
up vote
0
down vote
C# (.NET Core), 104 bytes
a=>{for(int i=2;;i++)if(System.Numerics.BigInteger.Pow(a,i).ToString().Contains(a.ToString()))return i;}
Try it online!
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 => {
for(int i = 2; ; i++) // starting from 2
if( System.Numerics.BigInteger.Pow(a,i) // n = a^i
.ToString().Contains(a.ToString()) ) // if n contains a
return i; // return i
}
add a comment |
up vote
0
down vote
up vote
0
down vote
C# (.NET Core), 104 bytes
a=>{for(int i=2;;i++)if(System.Numerics.BigInteger.Pow(a,i).ToString().Contains(a.ToString()))return i;}
Try it online!
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 => {
for(int i = 2; ; i++) // starting from 2
if( System.Numerics.BigInteger.Pow(a,i) // n = a^i
.ToString().Contains(a.ToString()) ) // if n contains a
return i; // return i
}
C# (.NET Core), 104 bytes
a=>{for(int i=2;;i++)if(System.Numerics.BigInteger.Pow(a,i).ToString().Contains(a.ToString()))return i;}
Try it online!
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 => {
for(int i = 2; ; i++) // starting from 2
if( System.Numerics.BigInteger.Pow(a,i) // n = a^i
.ToString().Contains(a.ToString()) ) // if n contains a
return i; // return i
}
answered 5 hours ago
Meerkat
2218
2218
add a comment |
add a comment |
up vote
0
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!
add a comment |
up vote
0
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!
add a comment |
up vote
0
down vote
up vote
0
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!
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!
answered 3 hours ago
Οurous
5,94311032
5,94311032
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176734%2fself-contained-powers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Related
– Skidsdev
8 hours ago
A045537
– Shaggy
6 hours ago