pythonchallenge(0-9)

来源:互联网 发布:淘宝上怎么买氰化钾 编辑:程序博客网 时间:2024/05/29 14:54

0.
2**38
  
1.
方法一:
input = "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."
 
def mymap(input):
    output = ''
    for in input:
        if 'a'<=and 'x'>=x:
            output += chr(ord(x) + 2)
        elif x=='y':
            output += 'a'
        elif x=='z':
            output += 'b'
        else:
            output += x
    print output
     
mymap(input)
mymap('map')
方法二:
import string
 
= "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."
 
leet = string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
 
print string.translate(s,leet)

2. http://www.pythonchallenge.com/pc/def/ocr.htm
import sys, urllib
import re
 
url = "http://www.pythonchallenge.com/pc/def/ocr.html"
wp = urllib.urlopen(url)
content = wp.read()
 
= re.compile(r'<!--([\s\S]*?)-->')
out = p.findall(content)[1]
res = [c for in out if c.isalpha()]
print ''.join(res)

3.http://www.pythonchallenge.com/pc/def/equality.html
恰好3个大写字母做保镖。
import sys, urllib
import re
 
url = "http://www.pythonchallenge.com/pc/def/equality.html"
wp = urllib.urlopen(url)
content = wp.read()
 
= re.compile(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')
out = p.findall(content)
 
print ''.join(out)

4. http://www.pythonchallenge.com/pc/def/linkedlist.php
import sys, urllib
import re
 
url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345"
output = open('result.txt','w')
 
for in range(400):
    print i
    output.write(url+'\n')
    content = urllib.urlopen(url).read()
    num = content.split()[-1]
    output.write(content+'\n')
    token = url.split('=')
    token[-1= '='+num
    url = ''.join(token)
     
output.close()
保存到文本中,再找规律。

5. http://www.pythonchallenge.com/pc/def/peak.html
import pickle
= open('banner.p')
data = pickle.load(f)
print '\n'.join(''.join(p[0]*p[1for in row) for row in data)
f.close()
我还以为要"pronounce it"音频处理呢。。结果"peakhell"暗示"pickle",用pickle load,然后' '与'#'恢复出字符组成的字channel.

6. http://www.pythonchallenge.com/pc/def/channel.html
import zipfile
 
currentfile = "90052.txt"
comment = []
with zipfile.ZipFile('channel.zip',mode='r') as zf:
        while(1):
                comment.append(zf.getinfo(currentfile).comment)
                data = zf.read(currentfile)
                nextnum = data.split()[-1]
                if str.isdigit(nextnum):     
                        currentfile = nextnum + '.txt'
                else:
                        print data
                        break
print ''.join(comment)
这道题我也是败给它了。先是领会出把url中的html换成zip, 这样就可以下载zip文件了(会自动弹出对话框下载),然后找到readme.txt根据提示,类似第5题一样往下搜索,最后结果是Collect the comments,原来每个zip文件都一个信息,信息里包含了comment。

7. http://www.pythonchallenge.com/pc/def/oxygen.html
from PIL import Image
 
img = Image.open('oxygen.png')
pix = img.load()
width = img.size[0]
center = img.size[1]/2
asi = ''
for in range(0, width,7):
    asi = asi + chr(pix[x, center][0])
print asi
 
= [105110116101103114105116121]
print ''.join([chr(i) for in l])

8. http://www.pythonchallenge.com/pc/def/integrity.html
import bz2
 
compressed_un = "BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084"
compressed_pw = "BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08"
decompressed_un = bz2.decompress(compressed_un)
decompressed_pw = bz2.decompress(compressed_pw)
 
print decompressed_un,decompressed_pw
解个压缩就过了。。比想象中容易一点,不过要看出un和pw是bz2压缩后的字符。(1.图片有一直蜜蜂,发音bee有提示 2.对bz2压缩后的形式熟悉)

0 0