def is_lychrel(n): start = n + rev(n) iterations = iterate(lambda x: x + rev(x), start) return not any(is_palindromic(y) for y in take(50, iterations))
def problem57(): generate_tails = iterate(tail, 2) # yields 2, tail(2), tail(tail(2)), ... expansions = (1 + Fraction(1, t) for t in generate_tails) return quantify(take(1000, expansions), pred=check_numerator)