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