Anonymous user
EKG sequence convergence: Difference between revisions
→{{header|Python}}: find_convergence as function
m (Whoops) |
(→{{header|Python}}: find_convergence as function) |
||
Line 83:
yield found[0], [n for n, _ in so_far]
last, last_pf = found
#%%
def find_convergence(ekgs=(5,7), limit=1_000):
"Returns the convergence point or zero if not found within the limit"
ekg = [EKG_gen(n) for n in ekgs]
for e in ekg:
ldiff = len(differ)
return ldiff + 2 if ldiff < limit-1 else 0
#%%
Line 88 ⟶ 98:
for start in 2, 5, 7:
print(f"EKG({start}):", str([n[0] for n in islice(EKG_gen(start), 10)])[1: -1])
▲ ekg5.__next__(), ekg7.__next__() # skip initial 1
▲ differ = list(takewhile(lambda state: state[0] != state[1],
▲ zip(ekg5, ekg7)))
▲ print(f"\nEKG(5) and EKG(7) converge at term {len(differ) + 2}!")</lang>
{{out}}
|