python challenge 过关心得 逐步更新

第零关:

 

很简单,算出2的38次方 

2**38
答案为:274877906944

第一关:


按照题意,就是把字母映射到后面的第二个字母,代码如下:

from string import maketrans
a=maketrans('','')[97:123]
b=list(a)
b.extend(['a','b'])
b.pop(0)
b.pop(0)
b=''.join(b)
table=maketrans(a,b)
print "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.".translate(table)

执行结果如下:

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.

于是乎对“map”进行同样的操作,得到ocr,进入下一关

第二关:

本题让我们看网页的源码文件,我们察看了之后就会发现有一大段文字是注释文字,这也就是题目和数据了


file = open('C://Users//tdk//Desktop//data.txt')
ans = ''
tmp = file.read()
for c in tmp:
	if c.isalpha():
		ans += c
print ans
执行结果为:

equality

进入下一关

第三关:


一个小写字母,每边刚好有三个大写字母做保镖。

同样,先察看源文件,发现数据还在里头:


代码如下:

import re
file = open('C://Users//tdk//Desktop//data.txt')
ans = ''
tmp = file.read()
pattern = "[a-z][A-Z][A-Z][A-Z][a-z][A-Z][A-Z][A-Z][a-z]"
temp = ''
for match in re.findall(pattern,tmp):
    temp += match[4]
print temp

执行结果为:

linkedlist

进入下一关,注意要写成linkedlist.php

第四关:



点击网页上的图片之后,进入连接


http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345


提示and the next nothing is 44827


然后就把12345改成44827,他又提示and the next nothing is 45439……


就这么一路下去,照着提示,几百次之后就行了……

当然要用程序的形式了,要不然网页也不会说Your hands are getting tired 

提示是用urllib模块

代码如下:

import urllib2
import re
r=re.compile(r'(\d+)$')
nextnothing='12345'
i=0
while(1):
   try:
       f=urllib2.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s'% nextnothing)
       result=f.read()
       f.close()
       print result
       oldnextnothing=nextnothing
       nextnothing=r.search(result).group()
       i+=1
   except:
       nextnothing=oldnextnothing

执行过程中还会发生这样的问题:


于是把它换成8022继续执行下去


于是得答案,进入下一关

第五关:


尽管页面提示我将 peak hell 读出声来,我还是没有意识到pickle这个词。
查看http://www.pythonchallenge.com/pc/def/banner.p,通过显示的数据才反应过来应该是pickle

import urllib2
import cPickle as pickle
import pprint
f=urllib2.urlopen('http://www.pythonchallenge.com/pc/def/banner.p')
result=pickle.Unpickler(f).load()
pprint.pprint(result)

执行结果为:


这种序列,观察可以得出是每一行各个字符序列及其显示的个数
然后将其显示出来,就有

import urllib2
import cPickle as pickle
import pprint
f=urllib2.urlopen('http://www.pythonchallenge.com/pc/def/banner.p')
result=pickle.Unpickler(f).load()
pprint.pprint(result)
output = open('output.txt', 'w')  
for line in result:  
    print >> output, ''.join([c[0]*c[1] for c in line])
output.close()

执行结果为:


因此答案是channel

进入下一关

第六关:


察看源文件:

The following has nothing to do with the riddle itself. I just 
thought it would be the right point to offer you to donate to the 
Python Challenge project. Any amount will be greatly appreciated. 

除了这点内容,源码中还有一段:<-- zip --> 比较奇怪,这下又难住了,只有再次上网找线索了………… 原来是将网页URL后缀名改成zip,改完后会下载一个ZIP文件,打开后有一堆的txt文件,线索就在其中的一个readme.txt里: 

welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip

打开90052.txt,内容是Next nothing is 94191,看来这题是跟第四题一样,找next nothing。同时要用到对ZIP的处理。 准备编程,将下载下来的channel.zip保存到本地环境。 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值