Skip to content

Instantly share code, notes, and snippets.

@mpfdev
Last active August 15, 2022 22:41
Show Gist options
  • Save mpfdev/fa0bdd2829053259ff88b8146193d0f0 to your computer and use it in GitHub Desktop.
Save mpfdev/fa0bdd2829053259ff88b8146193d0f0 to your computer and use it in GitHub Desktop.
def double_eights(n)
def double_eights(n):
"""Return true if n has two eights in a row.
>>> double_eights(8)
False
>>> double_eights(88)
True
>>> double_eights(2882)
True
>>> double_eights(880088)
True
>>> double_eights(12345)
False
>>> double_eights(80808080)
False
"""
"*** YOUR CODE HERE ***"
if n < 87:
return False
n_len = len(str(n))
n_last_digit = n // pow(10, n_len - 1)
n = n % pow(10, n_len - 1)
n_len -= 1
n_next_digit = None
while n_len != 0:
if(n < 10):
n_next_digit = n
if(n_last_digit == 8 and n_last_digit == n_next_digit):
return True
else:
return False
else:
n_next_digit = n // pow(10, n_len -1)
n = n % pow(10, n_len -1)
n_len -= 1
if(n_last_digit == 8 and n_last_digit == n_next_digit):
return True
else:
n_last_digit = n_next_digit
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment