Problem-51.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:Project-Euler 作者: XiaoTaoWang 项目源码 文件源码
def genMod(digitnum = 5):

    pool = range(digitnum)
    # The repeating part must be 3 or multiple of 3
    # The repeating part cannot include the last digit
    tset = set(range(digitnum-1))
    repeats = itertools.combinations(range(digitnum-1), 3)
    for r in repeats:
        rset = set(r)
        oset = tset - rset
        for i in r:
            pool[i] = '{0}'
        odigits = itertools.permutations('0123456789', len(oset))
        for o in odigits:
            idx = 0
            for i in oset:
                pool[i] = o[idx]
                idx += 1
            for last in ['1','3','7','9']:
                pool[-1] = last
                if pool[0] != '0':
                    yield ''.join(pool)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号