主页:http://www.pythonchallenge.com/
第一题:http://www.pythonchallenge.com/pc/def/0.html
>print pow(2,38)
>274877906944
第二题:http://www.pythonchallenge.com/pc/def/map.html
def tranChar(s):
if s==" " or s=="\'" or s==".":
t = s
elif s=="y":
t = "a"
elif s=='z':
t = 'b'
else:
t = chr(ord(s)+2)
return t
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."
s = ""
for i in str.strip(" "):
s = s+tranChar(i)
print s
经典解法:
print "".join(map(lambda x: x.isalpha() and chr((ord(x)+2-ord("a"))%26 + ord("a")) or x, input))
第三题:http://www.pythonchallenge.com/pc/def/ocr.html
tips:在该网页的源码找题目!
find rare characters in the mess below:
print "".join(map(lambda x: x.isalpha() and x or "",mess))
第四题:http://www.pythonchallenge.com/pc/def/equality.html
tips:在该网页的源码找题目!
reg = r'[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]'
re_mess_pattern = re.compile(reg)
r = re_mess_pattern.findall(mess)
print "".join(r)
第五题:http://www.pythonchallenge.com/pc/def/linkedlist.php
要解决的问题是:你点击哈图片,就知道了!
然后链接就变成了:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
import urllib,re,time
uri = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s"
reg = r"and the next nothing is (\d+)"
num = "8022"
while True:
try:
source = urllib.urlopen(uri % num).read()
# print source
num = re.search(reg,source).group(1)
print num
except:
break
print "Result is:",num
中间还要折腾两次~
第六题:http://www.pythonchallenge.com/pc/def/peak.html
还是看源码找问题:
peak hell sounds familiar ? 使用pickle
发现链接:http://www.pythonchallenge.com/pc/def/banner.p
import urllib,pickle
uri = 'http://www.pythonchallenge.com/pc/def/banner.p'
data = urllib.urlopen(uri)
tdata = pickle.load(data)
for i in tdata:
print "".join([j[1]*j[0] for j in i]) #j[1]表示生成#的个数,j[0]表示空格或者#
##### #####
#### ####
#### ####
#### ####
#### ####
#### ####
#### ####
#### ####
### #### ### ### ##### ### ##### ### ### ####
### ## #### ####### ## ### #### ####### #### ####### ### ### ####
### ### ##### #### ### #### ##### #### ##### #### ### ### ####
### #### #### ### ### #### #### #### #### ### #### ####
### #### #### ### #### #### #### #### ### ### ####
#### #### #### ## ### #### #### #### #### #### ### ####
#### #### #### ########## #### #### #### #### ############## ####
#### #### #### ### #### #### #### #### #### #### ####
#### #### #### #### ### #### #### #### #### #### ####
### #### #### #### ### #### #### #### #### ### ####
### ## #### #### ### #### #### #### #### #### ### ## ####
### ## #### #### ########### #### #### #### #### ### ## ####
### ###### ##### ## #### ###### ########### ##### ### ######
第七题:http://www.pythonchallenge.com/pc/def/channel.html
从这里下载zip包:http://www.pythonchallenge.com/pc/def/channel.zip
读zip包中的readme文件,可以知道题目意思和上面第5道题类似:
import urllib, zipfile, re, collections
o, n, f = [], "90052", "%s.txt"
nnr = "Next nothing is (\d+)"
# Download the ZIP file from http://www.pythonchallenge.com/pc/def/channel.zip
file = zipfile.ZipFile("channel.zip")
while True:
try:
n = re.search(nnr, file.read(f % n)).group(1)
except:
print file.read(f % n)
break
o.append(file.getinfo(f % n).comment)
print "".join(o)
这道题,貌似有些小问题,我是没有收集到comment信息.