网址:http://www.pythonchallenge.com/
解答好文:http://story.iteye.com/blog/730466
0:2^38
1 reduce(lambda x,y:x*y,[2]*38) #输入时不要输入L,只是表示类型为Long
1:位移两位
1 import string 2 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." 3 transfun=string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab') 4 print str.translate(transfun) 5 --> 6 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. 7 using string.maketrans() is recommended. now apply on the url. 8 9 *ord('A')可转化为ASCII码,chr(65)可转化为字符 10 但是注意最后两位y与Z不能用ASCII+2而是对应到a,b
2:page source即是源代码里面,写的有找最少
将那些字符复制到同路径名字为data的文件夹,采用伪木桶算法,这样每次操作都是O(1)
1 a={} 2 eleL=set(list('equality#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*@##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{$!@#$%)!@(&+^!{%_$&@^!}$_${)$_#)!({@!)(^}!*^&!$%_&&}&_#&@{)]{+)%*{&*%*&@%$+]!*__(#!*){%&@++')) 3 for i in eleL: 4 a[i] = 0 5 6 with open('data','r') as f: 7 str='' 8 for line in f.readlines(): #最好一行一行的处理,一起读出来太大容易卡电脑 9 line = list(line.strip()) #strip去掉换行符 10 for i in line: 11 a[i]+=1 12 print(a) 13 最后发现有几个字母都是只出现了一次:equality 14 **其实有个bug,equality这个词通过写是报Keyerror即可看出来了!!!第二行我是复制了三行进去再用set去重,报keyerror我才添加equality进去的
3:One small letter, surrounded by EXACTLY three big bodyguards on each of its sides:
找到一个周围被三个大写字母包围的小写字母(网页源代码中)
1 import re 2 with open('data','r') as f: 3 str = f.read().strip() 4 res=''.join()re.findall(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]',str)) #findall方法返回每个字母组成的list,[^]为不包含的意思 5 if(res): 6 print(res) 7 --->linkedlist
4:先点击图片后发现是个多级跳转,第一个参数是33110
1 from urllib import request 2 import re 3 value=33110 4 while True: 5 with request.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%d'%value) as f: 6 data = f.read().decode('utf-8') 7 res = re.findall(r'(d+)',data) 8 value = int(res[0]) 9 print(value) 10 最后得到66831,跳转后得到peak.html
5:这道题太扯了,peak hell连读成了pickle,pickle虽然知道但是从来没用过。
参考:
将page source里点击banner.p出现的东西保存成文件banner.p放到同目录下
序列化后出来是[[(' ', 95)], [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)], [(' ', 15), ('#', 4)]...]]根本就不知道是啥
输出成如下格式后:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 [[(' ', 95)], [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)], [(' ', 6), ('#', 3), (' ', 6), ('#', 4), (' ', 3), ('#', 3), (' ', 9), ('#', 3), (' ', 7), ('#', 5), (' ', 3), ('#', 3), (' ', 4), 2 [(' ', 95)] 3 [(' ', 14), ('#', 5), (' ', 70), ('#', 5), (' ', 1)] 4 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 5 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 6 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 7 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 8 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 9 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 10 [(' ', 15), ('#', 4), (' ', 71), ('#', 4), (' ', 1)] 11 [(' ', 6), ('#', 3), (' ', 6), ('#', 4), (' ', 3), ('#', 3), (' ', 9), ('#', 3), (' ', 7), ('#', 5), (' ', 3), ('#', 3), (' ', 4), ('#', 5), (' ', 3), ('#', 3), (' ', 10), ('#', 3), (' ', 7), ('#', 4), (' ', 1)] 12 [(' ', 3), ('#', 3), (' ', 3), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 2), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 1), ('#', 7), (' ', 3), ('#', 4), (' ', 1), ('#', 7), (' ', 5), ('#', 3), (' ', 2), ('#', 3), (' ', 5), ('#', 4), (' ', 1)] 13 [(' ', 2), ('#', 3), (' ', 5), ('#', 3), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 3), ('#', 4), (' ', 4), ('#', 5), (' ', 4), ('#', 4), (' ', 2), ('#', 5), (' ', 4), ('#', 4), (' ', 3), ('#', 3), (' ', 5), ('#', 3), (' ', 3), ('#', 4), (' ', 1)] 14 [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 4), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 6), ('#', 4), (' ', 2), ('#', 4), (' ', 1)] 15 [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 10), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)] 16 [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 5), ('#', 2), (' ', 3), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 7), ('#', 3), (' ', 2), ('#', 4), (' ', 1)] 17 [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 10), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 14), (' ', 2), ('#', 4), (' ', 1)] 18 [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)] 19 [('#', 4), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 12), ('#', 4), (' ', 1)] 20 [(' ', 1), ('#', 3), (' ', 11), ('#', 4), (' ', 5), ('#', 4), (' ', 1), ('#', 4), (' ', 5), ('#', 3), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 12), ('#', 4), (' ', 1)] 21 [(' ', 2), ('#', 3), (' ', 6), ('#', 2), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 3), (' ', 4), ('#', 4), (' ', 4), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 3), (' ', 6), ('#', 2), (' ', 3), ('#', 4), (' ', 1)] 22 [(' ', 3), ('#', 3), (' ', 4), ('#', 2), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 3), ('#', 11), (' ', 3), ('#', 4), (' ', 5), ('#', 4), (' ', 2), ('#', 4), (' ', 5), ('#', 4), (' ', 4), ('#', 3), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1)] 23 [(' ', 6), ('#', 3), (' ', 5), ('#', 6), (' ', 4), ('#', 5), (' ', 4), ('#', 2), (' ', 4), ('#', 4), (' ', 1), ('#', 6), (' ', 4), ('#', 11), (' ', 4), ('#', 5), (' ', 6), ('#', 3), (' ', 6), ('#', 6)] 24 [(' ', 95)]
考虑可能是空格画图,然后用了开头大神的代码
1 import pickle 2 with open('banner.p','r') as f: 3 object = pickle.load(f) 4 print object 5 for item in object: 6 print ''.join(map(lambda p: p[0]*p[1], item)) #此步最重要,我弄了半天没能看出来结果是channel
1 *此中有个值得思考的问题是若是用平时的读写文件,如一个文件保存了如下数据 2 [(' ',2),('#',1),(' ',1)] 3 [(' ',1),('#',3),(' ',1)] 4 [('#',5)] 5 应当还是用此地的原理每行读出后拼成字符串后打印。但有个问题是f.readlines()读出的是str型。那么如何转换成list呢? 6 import re 7 with open('banner.test','r') as f: 8 for line in f.readlines(): 9 result = re.findall(r"'(.)'.(.)",line) #用正则提取出来的元素刚好是成为list的元素,所以就完美的解决了这个问题 10 print type(result) 11 print ''.join(map(lambda x: x[0]*int(x[1]), result))
6:好吧,本以为和第四题一样提取到最后46154时出现see the comment.这完全不知道是啥
后来参考了别人的解法发现是zibfile模块在可提取文件头信息即是
但是很奇怪的是我的2.7.6老是报错没有ZipFile模块,就作罢了
7:
8:源代码中点击return/good.html会跳转到一个弹出框输入用户和密码的东东,而下面的东西自然就是usename与password了
<!--
un: 'BZh91AY&SYAxafx82
x00x00x01x01x80x02xc0x02x00 x00!x9ah3Mx07<]xc9x14xe1BAx06xbex084'
pw: 'BZh91AY&SYx94$|x0ex00x00x00x81x00x03$ x00!x9ah3Mx13<]xc9x14xe1BBPx91xf08'
-->
刚开始以为是不同的字符编码,用chardet模块可以看出编码:
import chardet
chardet.detect('BZh91AY&SYAxafx82
x00x00x01x01x80x02xc0x02x00 x00!x9ah3Mx07<]xc9x14xe1BAx06xbex084')
---->{'confidence': 0.365, 'encoding': 'windows-1252'} 关于windows-1252
故.decode('windows-1252')转化为unicode,但是显示还是无意义。后来发现原来是bz2压缩了的(关于bz2),用bz2模块解压即可
bz2.decompress('BZh91AY&SYAxafx82
x00x00x01x01x80x02xc0x02x00 x00!x9ah3Mx07<]xc9x14xe1BAx06xbex084')
最后得到huge与file分别为name与passwd