Project Euler 92

Source: Internet
Author: User


Import Itertoolsimport Timedef Conquer ():    ans = 0    digit_limit = 7    iter_str = "0123456789"    sum_square = LA MBDA Ss:sum (int (s) * * 2 for S in STR (ss))    fact = Lambda num:reduce (lambda x, y:x * y, xrange (1, num + 1))    combinations = itertools.combinations_with_replacement (iter_str,                                                            digit_limit)        def combinatorial_num ( num):        res = fact (digit_limit)        s = str (num) for        SS in Iter_str:            count = S.count (ss)            if Count > 1:res/= Fact (count)        return res for        C in combinations:        num = Int ("". Join (c))        if num = = 0:  Continue while        num! =, and num! = 1:            num = sum_square (num)        if num = =:            ans + = Combinatorial_num ( c)    Print Ansbegin = Time.time () conquer () end = Time.time () print End-begin

Project Euler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.