|
|
|
import itertools
|
|
|
|
|
|
|
|
length = 5
|
|
|
|
digits = set(range(10))
|
|
|
|
numbers = set(itertools.product(digits, repeat=length))
|
|
|
|
|
|
|
|
print(f"|Z| = {len(digits)}")
|
|
|
|
print(f"|N| = {len(numbers)}")
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
for n in numbers:
|
|
|
|
if len(set(n)) == 1:
|
|
|
|
counter += 1
|
|
|
|
print(f"|A| = {counter}")
|
|
|
|
# Ausgabe: |A| = 10
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
for n in numbers:
|
|
|
|
if sum(n.count(x) == 4 for x in set(n)) > 0:
|
|
|
|
counter += 1
|
|
|
|
print(f"|B| = {counter}")
|
|
|
|
# Ausgabe: |B| = 450
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
for n in numbers:
|
|
|
|
if len(set(n)) == 3 and any(n.count(x) == 3 for x in set(n)):
|
|
|
|
counter += 1
|
|
|
|
print(f"|C| = {counter}")
|
|
|
|
# Ausgabe: |C| = 7200
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
for n in numbers:
|
|
|
|
if len(set(n)) == 2 and any(n.count(x) == 3 for x in set(n)):
|
|
|
|
counter += 1
|
|
|
|
print(f"|D| = {counter}")
|
|
|
|
# Ausgabe: |D| = 900
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
for n in numbers:
|
|
|
|
if len(set(n)) == 3 and any(x != y and n.count(y) == 2 and n.count(x) == 2 for x in set(n) for y in set(n)):
|
|
|
|
counter += 1
|
|
|
|
print(f"|E| = {counter}")
|
|
|
|
# Ausgabe: |E| = 10800
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
for n in numbers:
|
|
|
|
if len(set(n)) == 5:
|
|
|
|
counter += 1
|
|
|
|
print(f"|F| = {counter}")
|
|
|
|
# Ausgabe: |F| = 30240
|
|
|
|
|
|
|
|
def contains_twin_pair(combo):
|
|
|
|
"""Check if the combination contains at least one twin pair."""
|
|
|
|
for x in range(len(combo)):
|
|
|
|
for y in range(len(combo)):
|
|
|
|
if abs(combo[x] % 49 - combo[y] % 49) == 1:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Generate all combinations of 6 numbers out of 49
|
|
|
|
numbers = list(range(1, 50))
|
|
|
|
all_combinations = list(itertools.combinations(numbers, 6))
|
|
|
|
|
|
|
|
# Filter combinations with and without twin pairs
|
|
|
|
combinations_with_twin = [combo for combo in all_combinations if contains_twin_pair(combo)]
|
|
|
|
combinations_without_twin = [combo for combo in all_combinations if not contains_twin_pair(combo)]
|
|
|
|
|
|
|
|
# Output the count of combinations
|
|
|
|
print(len(all_combinations))
|
|
|
|
print(f"Number of combinations with at least one twin pair: {len(combinations_with_twin)}")
|
|
|
|
print(f"Number of combinations without any twin pairs: {len(combinations_without_twin)}")
|
|
|
|
print(len(combinations_with_twin)/len(all_combinations))
|