Python Challenge解谜手记 Level0-1

本文深入解析PythonChallenge中Level0到Level1的解谜过程,通过简单的代码实现和逻辑推理,一步步揭示解题思路。从热身题到运用字符串操作,展示了如何通过Python解决编码挑战,特别强调了使用内置函数和API的高效性。文章还附带了源代码和翻译规则应用实例,旨在帮助读者理解并掌握Python挑战的核心概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作者: 晋哥哥 发表于 2010-05-29 18:12 原文链接 阅读: 971 评论: 7

很早就看到了http://www.pythonchallenge.com/,一直没往下做,后来发现还是蛮好玩的,所以在这里记录一下,希望能坚持走到最后的level。

Level 0

题目:238http://www.pythonchallenge.com/pc/def/0.html

题意:热身题,最简单的一道了吧,本意是熟悉挑战规则,即将答案替换掉当前url里的0.html

解谜:

 

<

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

> 1       print   2 << ( 38 - 1 )
2       print  pow( 2 , 38 )

 

 

可以用内建函数或者干脆移位操作,移位时要注意是38-1,因为题目是2乘以37个2,所以……不解释

 

Level 1

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

题意: 观察图中的映射规则,推断出应该是按照这种规则来翻译图下面的那句话,无论如何,先翻译一下吧。

解谜:

 

<

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

>  1      str  =   " 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. "
 2       for  c  in  str:
 3           if   not  c >= ' a '   and  c <= " z " :
 4              sys.stdout.write(c),
 5               continue
 6           if  c  ==   ' y ' :
 7               print   ' a ' ,
 8           elif  c  ==   ' z ' :
 9               print   ' b ' ,
10           else :
11              sys.stdout.write(chr(ord(c) + 2 ))

 

 

很挫, 翻译后得知:

 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.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.

大意就是,按照相同的规则对当前url进行翻译,得出下一题的url。不过题目推荐了maketrans(),笔者对python也是个半瓶水,很多api不熟,翻了翻文档,于是决定用最python的方式再来一次:

<

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

> 1       import  string
2      table  =  string.maketrans(string.ascii_lowercase, " cdefghijklmnopqrstuvwxyzab " );
3       print  string.translate(str, table)
4       print  string.translate( " http://www.pythonchallenge.com/pc/def/map.html " ,table)

 

得到:jvvr://yyy.ravjqpejcnngpig.eqo/re/fgh/ocr.jvon

那么下一题应该就是:http://www.pythonchallenge.com/pc/def/ocr.html

Python Challenge提供了参考代码,可以将当前url里的/pc改成/pcc来查看上一题的参考代码,所以Level1的参考代码可以查看:http://www.pythonchallenge.com/pcc/def/ocr.html

 

看了之后我发现我有一个地方确实不太简洁,忘了python那无敌的切片了,特此修正: 

<

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

> 1  table  =  string.maketrans(string.ascii_lowercase,string.ascii_lowercase[ 2 :] + string.ascii_lowercase[: 2 ])

 

 

评论: 7 查看评论 发表评论

购买博客园2010T恤,留下2010年的纪念


最新新闻:
· 迈过社会化网络:互联网的新时代(2010-07-21 21:19)
· 戴尔新推安全浏览器 基于Firefox 3.6(2010-07-21 21:02)
· 微软研究员认为密码可以简单又安全(2010-07-21 20:58)
· 苹果称80%财富100强企业已在使用iPhone(2010-07-21 20:54)
· 苹果10亿美元的数据中心将于今年建成,官方尚未对其用途表态(2010-07-21 17:51)

编辑推荐:程序员技术问答平台

网站导航:博客园首页  个人主页  新闻  闪存  小组  博问  社区  知识库

转载于:https://my.oschina.net/shoru/blog/6205

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值