Python Challenge解谜手记 Level0-1

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

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

Level 0

题目:238(http://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)

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

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

你可能感兴趣的:(Python Challenge解谜手记 Level0-1)