JanetZ

第 32 位会员
注册于 2020-04-18 22:50:46
活跃于 2020-09-24 15:15:12


最近话题
没有任何数据~~
最新评论
  • python 编程练习——吉尔布雷斯的有趣猜测 at 2020-05-21 14:00:50
    import numpy as np
    numbers = np.arange(1,65)
    length = len(numbers)
    n_max = int(np.sqrt(length))
    is_prime = np.ones(length,dtype = bool)
    is_prime[0] = False
    for i in range(2,n_max):
        if i in numbers[is_prime]:
            is_prime[(i**2-1)::i] = False
    prime = numbers[is_prime].tolist()
    print(prime,end="")
    row=[]
    result=[]
    for j in range(len(prime)):
        for i in range(len(prime)-1):
            row.append(np.abs(prime[i]-prime[i+1]))
        prime = row
        result.append(prime)
        if len(row) < 2 :
            break
        else:
            row = []
    r = 4
    for i in result:
        print("\n" + (2*r-1) * " " + str(i),end=" ")
        r += 1
  • python 编程练习——吉尔布雷斯的有趣猜测 at 2020-05-21 11:46:45
    [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61]
           [1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2] 
             [1, 0, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 2, 2, 0, 4] 
               [1, 2, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 4] 
                 [1, 2, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 2, 2] 
                   [1, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0] 
                     [1, 2, 0, 0, 2, 2, 0, 0, 2, 2, 2, 2] 
                       [1, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0] 
                         [1, 2, 2, 2, 2, 2, 2, 2, 0, 0] 
                           [1, 0, 0, 0, 0, 0, 0, 2, 0] 
                             [1, 0, 0, 0, 0, 0, 2, 2] 
                               [1, 0, 0, 0, 0, 2, 0] 
                                 [1, 0, 0, 0, 2, 2] 
                                   [1, 0, 0, 2, 0] 
                                     [1, 0, 2, 2] 
                                       [1, 2, 0] 
                                         [1, 2] 
                                           [1] 
  • python 编程练习——一种密码方法:逆矩阵的应用 at 2020-05-21 11:45:17
    请输入想要加密的明文:Hill on Tuesday
    密文为:mcqcolftncnzvxe
    是否需要解密?(Y/N)
    Y
    解密结果为:Hill On Tuesday
  • python 编程练习——一种密码方法:逆矩阵的应用 at 2020-05-21 11:43:01
    import numpy as np
    letters = [' ','A','B','C','D','E','F','G','H','I','J','K','L','M',
               'N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
    word_standard = []
    save_numbers=[]
    read_number=[]
    return_word=[]
    decode=''
    codes=''
    word=input("请输入想要加密的明文:")
    word_standard.append(word.upper())
    for i in (','.join(word_standard)):
        for j in range(len(letters)):
            if i == letters[j] :
                save_numbers.append(j)
    row = len(save_numbers) / 3
    M = np.mat(np.array(save_numbers).reshape(int(row),3))
    A=np.mat([[-1,0,1],
             [1,-1,1],
             [1,1,0]])
    MA = M*A
    return_number=MA.tolist()
    for m in return_number:
        for n in range(len(m)):
            read_number.append(m[n])
    for i in read_number:
        codes += letters[i]
    print("密文为:" + codes.lower())
    print("是否需要解密?(Y/N)")
    judge = input()
    if judge == 'N':
        exit()
    else:
        m = (MA*A.I).tolist()
        for a in m:
            for b in range(len(a)):
                return_word.append(round(a[b]))
    for a in return_word:
        decode += letters[a]
    print("解密结果为:" + decode.title())