Find the least n such that the number 2 n contain 3 consecutive 6's, " 6 6 6 ".
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
i really like your solutions ^^
1 2 3 4 5 6 7 |
|
Avoiding the use of strings and of exponentiation, both of which are expensive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
I do agree that string conversion is expensive but for weird reasons, it's actually faster.
Log in to reply
Ah, very interesting. I must try timing it sometime.
Log in to reply
Here are the results -
1 |
|
1 |
|
Log in to reply
@Arulx Z – Here are some of my timings too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
In each case the first timing is for my original code, the second using equivalent string code. You're absolutely right. I'm old enough (69 in less than a week's time) that I should know never to depend on my intuitions.
Here is my code (Python 3):
def iscons(n):
for i in range(0,len(str(n))-2):
if int(str(n)[i])==6 and int(str(n)[i+1])==6 and int(str(n)[i+2])==6:
return True
else:
pass
return False
n=1
while n>0:
if iscons(2**n)==True:
print (n)
break
else:
n+=1
Problem Loading...
Note Loading...
Set Loading...