#!/usr/bin/env python import time from decimal import Decimal def mul(s): m = Decimal('1') for c in s: m *= Decimal(c) return str(m) count = lambda s, c=0: (s, c) if len(s) < 2 else count(mul(s), c+1) judge = lambda s, mc, r, c: (c > mc, s, r, max(c, mc)) calc = lambda s, mc: judge(s, mc, *count(s)) next_str = lambda s: str( Decimal(s) + 1 ) if __name__ == "__main__": st = time.time() (s, c) = ('0', 0) while True: (f, s, r, c) = calc( next_str(s), c ) if f: tm = time.time() - st print('{}, {}, {} # {} sec'.format(s, r, c, tm)) # EOF