Skip to content

Instantly share code, notes, and snippets.

@Motoma
Created March 9, 2011 14:51
Show Gist options
  • Select an option

  • Save Motoma/862309 to your computer and use it in GitHub Desktop.

Select an option

Save Motoma/862309 to your computer and use it in GitHub Desktop.
class BaseSevenNumber:
def __init__(self):
self.digits = [1]
def Double(self):
for i in range(0, len(self.digits)):
self.digits[i] = self.digits[i] * 2
for i in range(len(self.digits) - 1, -1, -1):
if self.digits[i] > 6:
self.digits[i] = self.digits[i] - 7
if i == 0: self.digits.insert(0,1)
else: self.digits[i - 1] = self.digits[i - 1] + 1
def HasThreeZeros(self):
for i in range(0, len(self.digits) - 2):
if self.digits[i] == 0 and self.digits[i + 1] == 0 and self.digits[i + 2] == 0:
return True
return False
def SolveRiddle(maxFailuresAssumeFound):
bsn = BaseSevenNumber()
failures = 0
power = 1
while failures < maxFailuresAssumeFound:
bsn.Double()
if bsn.HasThreeZeros(): failures = failures + 1
else:
failures = 0
print power
power = power + 1
SolveRiddle(10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment