Я пытался запустить его в Google Colab, но это заняло гораздо больше времени, чем я ожидал. Я собираюсь оставить его работать на ночь, но мне хотелось иметь альтернативное решение.
def count_combinations(n, prev, count):
if n == 0:
return count + 1 # We have reached the end of the combination, increment count
new_count = 0
# Try adding numbers from 1 to 16, excluding prev if possible
for num in range(1, 17):
if num != prev and (num != prev + 1 or num != prev - 1):
new_count += count_combinations(n - 1, num, count)
return new_count
# Initialize count with 0 and start with any number (except 10 because we need to end with 10)
total_count = count_combinations(15, 0, 0)
print("Total valid combinations:", total_count)
Подробнее здесь: https://stackoverflow.com/questions/784 ... hon-script