不服来战, Python趣味挑战赛

640?wx_fmt=jpeg

www.pythonchallenge.com, 它是一个在线的 Python 技术挑战平台,一共有33道关卡,你只有正确回答了第一道题才能看到第二道题,依此类推

第一次使用这个网站估计你弄不明白怎么玩,因为每道题就是一张图,你要根据每道题的提示信息算出正确答案,正确答案就是下一道题的入口

第一题

640?wx_fmt=jpeg

它的答案其实就是将2的38次方的结果作为下一道题的入口链接,因为 2**38 等于 274877906944,所以第二道题的链接地址就是将这道题的链接

http://www.pythonchallenge.com/pc/def/0.html
替换成:
http://www.pythonchallenge.com/pc/def/274877906944.html

第二题

打开链接后会重定向到新的页面,出现的图是:

640?wx_fmt=png

先用代码实现可以得到解密算法:

def decrypt(c):
return chr(((ord(c) + 2) - ord('a')) % 26 + ord('a'))

将加密字符串进行解密得到:

>>> s = """

everybody thinks twice before solving this.

g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.

"""
>>> result = ""
>>> for c in raw:
...     if c >= 'a' and c <= 'z':
...         result += decrypt(c)
...     else:
...         result += c

最后解密出result为(代码可右划):

i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.

它告诉我们不要等手动的去转换,而是用一种算法来实现,因为遇到很长的字符串时手动转换的效率不高,另外它还给了我们另一种方法就是使用 string.maketrans() 进行转换,所以就有了第二种解法:

>>> t = str.maketrans("abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab")
>>> s.translate(t)
"i hope you didnt translate it by hand. thats what computers are for. doing itin by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url."

我们将该算法应用到该url

http://www.pythonchallenge.com/pc/def/map.html

将被转换成

http://www.pythonchallenge.com/pc/def/ocr.html

该链接就是第三题的入口

第三题

640?wx_fmt=png

推荐阅读:

640?

如果喜欢本文,欢迎关注并置顶公众号

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值