"""Exact arithmetic model of Day 22/24 choices; no visitor data.""" from fractions import Fraction as F import json def recover(start, length): a, w, path = F(0), F(1), '' while (a, w) != (start, length): cut = a + w/3 if start + length <= cut: path += 'L'; w /= 3 elif start >= cut: path += 'R'; a = cut; w *= F(2,3) else: raise ValueError('Target crosses a division') if len(path)>11: raise ValueError('Unreachable interval') return path rows=[] def walk(a,w,path): decoded=recover(a,w) assert decoded==path terminal=w