zoukankan      html  css  js  c++  java
  • 竖式谜题

    对于一道数字谜题,人很容易观察出一些特点,从而缩小枚举范围。

    对于程序,它如果能够像人一样分析这样的问题,那就能够极大地减少搜索空间。
    人在计算时,是一种模糊计算,是一种由模糊逐渐清晰的过程。
    当人计算两个数字的乘积时,先大约估计出乘积,而不是一次性精确算出。
    如何让计算机模拟人脑进行数值计算的过程?

    • 如何出题才能防止暴力破解?
    • 对于两串大整数字谜,如何快速找到一对解?
    import collections
    
    """
    题目生成器
    """
    N = 2
    
    
    def put(puzzle, one, a):
        """
        将数字转化为字母
        :param puzzle:
        :param one:
        :param a: 数字到字母的映射
        :return:
        """
        s = ''
        for i in str(one):
            if i not in a:
                a[i] = chr(ord('A') + len(a))
            s += a[i]
        puzzle.append(s)
    
    
    def getall():
        all_puzzles = []
        ans = []
        for i in range(10 ** (N - 1) + 1, 10 ** N):
            for j in range(10 ** (N - 1) + 1, 10 ** N):
                if '0' in str(i) or '0' in str(j): continue
                a = dict()
                puzzle = []
                put(puzzle, i, a)
                put(puzzle, j, a)
                for k in range(N):
                    put(puzzle, i * (j // (10 ** k) % 10), a)
                put(puzzle, i * j, a)
                all_puzzles.append(puzzle)
                ans.append((i, j))
        return all_puzzles, ans
    
    
    def filt():
        x, y = getall()
        m = list(map(lambda x: ','.join(x), x))
        cnt = collections.Counter(m)
        nx = []
        ny = []
        for i in range(len(m)):
            if cnt[m[i]] == 1:
                nx.append(tuple(x[i]))
                ny.append(y[i])
        return dict(zip(nx, ny))
    
    
    def get_ans(s: str):
        return puzzles.get(tuple(s.split(',')))
    
    
    puzzles = filt()
    print("一共有", len(puzzles), "道题目")
    
  • 相关阅读:
    Ajax基础:3.Json
    Head First Design Patterns State Pattern
    Head First Design Patterns Template Method Pattern
    Articles For CSS Related
    Head First Design Patterns Decorator Pattern
    代码审查工具
    How To Be More Active In A Group
    Head First Design Patterns Factory Method Pattern
    Head First Design Patterns Composite Pattern
    Tech Articles
  • 原文地址:https://www.cnblogs.com/weiyinfu/p/10205448.html
Copyright © 2011-2022 走看看