您的位置:首页 > 编程语言 > Python开发

pythonchallenge(0-9)

2015-12-18 20:18 701 查看
0.

2**38

1.

方法一:

input
=
"g fmncwmsbgblr rpylqjyrcgr zw fylb. rfyrq ufyr amknsrcpq ypcdmp.\


bmgle gr glzw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.\


kyicrpylq() gq pcamkkclbcb. lmu ynnjw mlrfcspj."


def
mymap(
input
):


output
=
''


for
x
in
input
:


if
'a'
<
=
x
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


s
=
"g fmncwmsbgblr rpylqjyrcgr zw fylb. rfyrq ufyr amknsrcpq ypcdmp.\


bmgle gr glzw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.\


kyicrpylq() gq pcamkkclbcb. lmu ynnjw mlrfcspj."


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()


p
=
re.
compile
(r
'<!--([\s\S]*?)-->'
)


out
=
p.findall(content)[
1
]


res
=
[c
for
c
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()


p
=
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
i
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


f
=
open
(
'banner.p'
)


data
=
pickle.load(f)


print
'\n'
.join(''.join(p[
0
]
*
p[
1
]
for
p
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'
) aszf:


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
x
in
range
(
0
,width,
7
):


asi
=
asi
+
chr
(pix[x,center][
0
])


print
asi


l
=
[
105
,
110
,
116
,
101
,
103
,
114
,
105
,
116
,
121
]


print
''.join([
chr
(i)
for
i
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压缩后的形式熟悉)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: