def find_10_10_tours():
n = 16
solutions = []
def backtrack(seq):
# If we've built a sequence of length 10:
if len(seq) == n:
# Check if it ends with 9:
if seq[-1] == 15:
solutions.append(seq[:]) # Store a copy of this valid tour
return
used = set(seq)
# Try all possible next values from 1..10
for next_val in range(1, n+1):
if next_val not in used:
# We only allow next_val if it can be expressed
# as a_i - a_j for some i,j < current length,
# with a_i > a_j.
valid = False
# For l < 3, we can skip the difference check if l=2?
# Actually, the problem states "for l >= 3," so for the second position
# (index 1 in Python), there is no difference requirement yet.
# We'll handle that condition carefully:
if len(seq) < 2:
# If we haven't placed the second element yet,
# there's no difference requirement. We can pick anything not used.
valid = True
else:
# Now we must see if next_val is a difference of two earlier terms
for i in range(len(seq)):
for j in range(len(seq)):
if i != j and seq[i] > seq[j]:
if seq[i] - seq[j] == next_val:
valid = True
break
if valid:
break
if valid:
seq.append(next_val)
backtrack(seq)
seq.pop()
# We start the sequence with a1 = 10
initial_seq = [16]
backtrack(initial_seq)
return solutions
# --- Run the search and display results ---
all_tours = find_10_10_tours()
print("All (10,10)-tours found (each sequence of length 10):")
for tour in all_tours:
print(tour)
print(f"\nTotal number of (10,10)-tours found: {len(all_tours)}")