You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to understand what kind of crazy magic you're using for the twenty-sixth problem, specifically this little black box of black magic:
def reciprocal_cycle_len(n):
seen = {}
x = 1
for i in itertools.count():
if x in seen:
return i - seen[x]
else:
seen[x] = i
x = x * 10 % n
It's the simplest thing I've ever seen that I just can't figure out. I guess I'm just not good with numerology. Is there a spatial relationship that would make sense?
The text was updated successfully, but these errors were encountered:
It is a finite state machine that simulates dividing 1.000000... by n. In each iteration, x is the current remainder in the division, which is an integer between 1 and n-1 (inclusive).
It is a finite state machine that simulates dividing 1.000000... by n. In each iteration, x is the current remainder in the division, which is an integer between 1 and n-1 (inclusive).
Hi, I'm trying to understand what kind of crazy magic you're using for the twenty-sixth problem, specifically this little black box of black magic:
It's the simplest thing I've ever seen that I just can't figure out. I guess I'm just not good with numerology. Is there a spatial relationship that would make sense?
The text was updated successfully, but these errors were encountered: