python challenge 14解题总结

python challenge 14网址:www.pythonchallenge.com/pc/return/italy.html

根据网页标题的提示:walk around,网页代码的提示:100*100 = (100+99+99+98) + (…,还有那张螺旋状的面包图片,猜测,要把下面那张图(其实这个图是10000*1的,居然能显示成方的)以这种形式展开:

import PIL.Image
def nextpoint(direction,oldpoint):
        if direction==0:
            return oldpoint+1
        elif direction==1:
            return oldpoint+100
        elif direction==2:
            return oldpoint-1
        elif direction==3:
            return oldpoint-100
        else:
            print 'wrong!'
im=PIL.Image.open('wire.png')
newim=PIL.Image.new(im.mode,[100,100])
context=list(im.getdata())
result=[1]*10000
result[0:100]=context[0:100]
p=100
i=1
nextp=0
oldpoint=99
for v in range(99,0,-1):
        for q in range(v,0,-1):
                nextp=nextpoint(i,oldpoint)
                result[nextp]=context[p]
                p=1+p
                oldpoint=nextp
        i=(i+1)%4
        for q in range(v,0,-1):
                nextp=nextpoint(i,oldpoint)
                result[nextp]=context[p]
                p=1+p
                oldpoint=nextp
        i=(i+1)%4        
newim.putdata(result)
newim.save('w2.png')


下一关地址:www.pythonchallenge.com/pc/return/cat.html 页面显示uzi,于是输入网址:www.pythonchallenge.com/pc/return/uzi.html

需要的用户名密码为:huge(用户名),file(密码)