29. http://www.pythonchallenge.com/pc/ring/guido.html
标题是silence! 图片名称是woisit. 图片有点像一个人。应该是猜一种职业。
注意到,源文件里有大量空格,每行的空格数还不一样。把空格数转换成ascii码再用bz2解码。
import urllib
import bz2
content = urllib.urlopen(url).read()
content = content.split(
'\n'
)[12:]
t =
''
.join([chr(len(line))
for
line
in
content])
print bz2.decompress(t)
结果:Isn't it clear? I am yankeedoodle!(yankee doodle一首雄赳赳气昂昂的歌~)
30. http://www.pythonchallenge.com/pc/ring/yankeedoodle.html
图片似乎没什么信息,还让你放松relax...来到30关也不容易。
下了一个csv文件,是一些数字。
7367个浮点数,*256变成53*139的图片。
import Image
imsize = (53,139)
new
= Image.
new
(
'L'
, imsize, 0)
data = open(
'yank.csv'
,
'r'
).read().split(
','
)
N = len(data)
for
i
in
range(N):
pixel = float(data[i])*256
print (i%imsize[0], i/imsize[0])
new
.putpixel((i%imsize[0], i/imsize[0]), int(pixel))
new
=
new
.transpose(Image.ROTATE_90)
#图像旋正
new
=
new
.transpose(Image.FLIP_TOP_BOTTOM)
new
.show()
得到了一个公式
这图片不好认,还旋了几下才正。n=str(x[i])[5]+str(x[i+1])[5]+str(x[i+2])[6]
如果x[i]是指csv里的浮点数的话。0.82207, 0.91181, 0.88563 则 n为086
data = open(
'yank.csv'
,
'r'
).read().split(
','
)
data = map(lambda x: x.strip(), data)
t = [data[i][5]+data[i+1][5]+data[i+2][6]
for
i
in
range(0,len(data)-2,3)]
print
''
.join([chr(int(i))
for
i
in
t])
数据读取不熟练...
结果:
So, you found the hidden message.
There is lots of room here for a long message, but we only need very little space to say "look at grandpa", so the rest is just garbage.
VTZ.l'tf*Om@I"p]#R`cWEBZ40ofSC>OZFkRP0\)+b?Ir)S%Jt3f{ei%n2<FErFx~...一堆乱码。
居然grandpa就过了。。。后面的是干嘛?留着以后用?还是garbage(垃圾)?
31. http://www.pythonchallenge.com/pc/ring/grandpa.html
一堆石头。。题目:where am I?
<!-- short break, this ***REALLY*** has nothing to do with Python -->
和python无关,难道猜测石头的风景区是哪里?
这又是一个找用户名密码的题。google搜图,还真是泰国的一处旅游景点(阿公石), 用户名kohsamui,密码thailand.
(题外话,我用谷歌百度都搜了,谷歌出来阿公石,百度乱七八糟的石头(夹杂一两幅阿公石)。谷歌搜图做得比百度好)
可是,并没有过,
That was too easy. You are still on 31...
ti
题目UFOs? 图片名称mandelbrot(分形图形)
利用给定的参数画分形图。(分形图行绘制参考链接 http://old.sebug.net/paper/books/scipydoc/fractal_chaos.html)
和原图很相似,有少量像素不一样,差值为正负16. 一共1679个,因式分解23*73(唯一分解),利用正负号不同再构造出一幅图。
import Image
imgbase = Image.open(
'mandelbrot.gif'
)
img = imgbase.copy()
left = 0.34
top = 0.57+0.027
width = 0.036
height = 0.027
max = 128
diff = []
for
j
in
range(imgbase.size[1]):
for
i
in
range(imgbase.size[0]):
point0 = complex(left + i*width/imgbase.size[0], top - (1+j)*height/imgbase.size[1])
point = 0+0j
for
k
in
range(max):
point = point **2 + point0
if
point.imag**2+point.real**2>4:
break
img.putpixel((i,j),k)
if
k!=imgbase.getpixel((i,j)):
diff.append(k - imgbase.getpixel((i,j)))
img.save(
'out31.png'
)
img2 = Image.
new
(
'1'
,(23,73))
img2.putdata([i<0
for
i
in
diff])
img2.save(
'out31_2.png'
)
最后得到一个这个图形
谷歌搜图,arecibo message
32. http://www.pythonchallenge.com/pc/rock/arecibo.html
提示1.
<!-- you are in level 32 --> (正面图上没有32.所以这里提示,无解题信息)
提示2.
<!-- for warmup.txt -->
提示3.
Fill in the blanks
题目etch-a-scetch是一种画图共具,详见 https://www.youtube.com/watch?v=nYM__s3R5q0
一种叫Nonogram的游戏,代码有点长,今天先不写。。
33. http://www.pythonchallenge.com/pc/rock/beer.html
提示1.
|
If you are blinded by the light, |
|
remove its power, with its might. |
|
Then from the ashes, fair and square, |
|
another truth at you will glare. |
|
提示2. beer1.jpg 下载得beer2.png 结合下载的图片,提示1,应该是对像素做处理。 把较亮的像素移除,然后用剩下的像素(像素总数应该是平方)重新组成一幅新图。 |
|
|
最后一关,不着急。先看图片大小138*138 |
|
from PIL import Image
import math
im = Image.open(
'beer2.png'
)
print im.size
total = im.size[0] * im.size[1]
histogram = im.histogram()
ashes = total
for
i
in
range(len(histogram)-1, 0, -1):
ashes = ashes - histogram[i]
print histogram[i]
if
histogram[i] != 0 and math.sqrt(ashes) == int(math.sqrt(ashes)):
print ashes, i
break
不断去掉最亮的两个像素值,剩下最亮的打开,其余关掉。再去掉最亮的两个,如此循环……
from PIL import Image
import math
im = Image.open(
'beer2.png'
)
im.load()
data = list(im.getdata())
#原始图像像素
ashes = [i
for
i
in
data
if
i < 193]
#去掉最高两组
s = sorted(list(set(ashes)))
for
i
in
range(len(s)-1, 0, -2):
size = math.sqrt(len(ashes))
print size
new
= Image.
new
(
'1'
, (int(size),int(size)))
#新建图像
new
.putdata([j==s[i]
for
j
in
ashes])
new
.save(
'pictures/%d.jpg'
%i) #注意,事先的pictures文件夹要建好,python不能自动建文件夹
ashes = [pixel
for
pixel
in
data
if
pixel < s[i-1]]‘
gremlins。
终于全部过关
还蛮好玩的一个游戏~我会想你的::>_<::