Created
April 23, 2024 17:09
-
-
Save ibernabel/42c22b8b66b67acd2b1026e225f73ed4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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