Mike M. answered 17d
Data Scientist | 20+ Yrs in ML, Python, SQL, and Real-World Modeling
mapping = {
# create mapping for 0 -9 from the provided data
# ie 0:6...
}
def trace_chain(start):
"""Follow the mapping until it repeats."""
seen = []
current = start
while current not in seen:
seen.append(current)
current = mapping[current]
seen.append(current) # show where it loops back
return seen
# Print chains for all digits
for n in range(10):
chain = trace_chain(n)
chain_str = " → ".join(map(str, chain))
print(f"{n}: {chain_str}")