def _chain( self, n ): t= n visited= set() while t not in self.memoized: t= sum( d*d for d in digits(t) ) visited.add(t) # Set all the numbers in this chain to point to the same result for u in visited: self.memoized[u]= self.memoized[t] return self.memoized[t]
def _chain( self, n ): while self.memoized[n] == 0: n= sum( d*d for d in digits(n) ) return self.memoized[n]