verwijder mijn topic
There are 10 digits 0-9.
If you have 6 of them, that’s 106.
What exactly do you mean by double digits? Do you mean 2 digits the same next to each other or just 2 (or more?) digits the same?
1 Like
no I mean it’s a 6 digit PIN. I completely forgot about him. it is a code combination from 1 to 9 but I think it started with 1, 3, 7 or 9. I just understood from a friend that you can’t just use the Python software that I need someone who has this skill! is this correct? I’m not that smart… I’m almost ashamed, and I have no other option than to seek help here
The original question was:
How many 6-digit numbers containing only the digits 1-9, where no adjacent digits are equal, exist?
Here is a brute-force solution to generate all such numbers:
def six_digits_1_9(starts_with=None):
start = 111111
stop = 999999
starts_with = range(1, 10) if starts_with is None else starts_with
for d in range(start, stop + 1):
if "0" in str(d):
continue
if any(i == j for i, j in zip(str(d), str(d)[1:])):
continue
if int(str(d)[0]) not in starts_with:
continue
yield d
list(six_digits_1_9()) # 294912 possibilities
list(six_digits_1_9([1, 3, 7, 9])) # 131072 possibilities