Python算法笔试题目,破解Hash值,N进制法

这是一篇关于如何使用N进制方法解决Python算法笔试题目的文章。题目要求找到一个特定哈希值对应的8位字符串,字符串仅包含字符'c', 'e', 'i', 'a', 'r', 'w', 'u', 's', 'p'。文中给出了哈希函数的实现,并提供了通过递归、非递归栈和动态规划三种可能的解决方案。作者通过模拟哈希函数计算过程,最终找到了字符串'surprise'。" 109992953,10270754,Python高阶函数深度解析:迭代器、装饰器与面向对象,"['Python编程', '函数式编程', '面向对象', '内存管理']
摘要由CSDN通过智能技术生成

Find the string whichhas this hash: 25267566250558

The string has length8.

Characters can befrom: c,e,i,a,r,w,u,s,p

The hash functionworks like this:

hash(str):

    1.LETTERS = c, e, i, a, r, w, u, s, p

    2. h =7

    3. forc in str:

        1.i = index of c in LETTERS

        2.h = 37 * h + i

    4.return h

Please send us thestring you found, and the code you used to find it.

使用N进制的解法的核心思想是:首先计算出解法的总数(possibilitites),然后从0到possibilitites遍历,将每一个遍历到的结果转换为N进制(这里N是8)。

代码如下:

#coding=utf-8
 
# for every possiblity , hexadecimal convertion is involved, its complexity is O("pow()*len(需要的字符串的长度)" *每次hash的计算量)
 
## correct: I found 'surprise' when  the index of c in LETTERS begins from 0
# 'uwasaeuc' when 1
#===========&#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值