Skip to content

Instantly share code, notes, and snippets.

@ibernabel
Created April 23, 2024 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibernabel/42c22b8b66b67acd2b1026e225f73ed4 to your computer and use it in GitHub Desktop.
Save ibernabel/42c22b8b66b67acd2b1026e225f73ed4 to your computer and use it in GitHub Desktop.
def count_numbers_without_adjacent_repeats():
# Initialize count to 0
count = 0
# Loop through all possible numbers from 000000 to 999999
for num in range(1000000):
print(num)
# Convert the number to a string
num_str = str(num).zfill(6)
# Check if the number has adjacent repeating digits
has_repeats = False
for i in range(5):
if num_str[i] == num_str[i+1]:
has_repeats = True
break
# If the number has no adjacent repeating digits, increment the count
if not has_repeats:
count += 1
#print(num_str)
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment