2014年10月3日 星期五 晴

Level9 http://www.pythonchallenge.com/pc/return/good.html un: huge pw: file

映入人眼的是图片中的一系列黑点,页面Title是connect the dots。Html Resource直接抛出问题,first+second=?,然后给出两个列表first和second,数字都是超过255的,a的长度是442,b的长度是112。题目应该是按时连点成线,会出来一个图形。

肉眼观察first和second,没看出来什么,长度不一样,不可能一个是横坐标而另一个是纵坐标。又看len(first)和len(second)两者的长度都是偶数,会不会是每个列表的是由一系列的 (x,y,x,y,x,y,x,y….)这样排列呢?

我的代码: [code]def Challenge9(): import Image,ImageDraw

first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170,310,171,301,173,290,178,289,182,287,188,286,190,286,192,291,194,296,195,305,194,307,191,312,190,316,190,321,192,331,193,338,196,341,197,346,199,352,198,360,197,366,197,373,196,380,197,383,196,387,192,389,191,392,190,396,189,400,194,401,201,402,208,403,213,402,216,401,219,397,219,393,216,390,215,385,215,379,213,373,213,365,212,360,210,353,210,347,212,338,213,329,214,319,215,311,215,306,216,296,218,290,221,283,225,282,233,284,238,287,243,290,250,291,255,294,261,293,265,291,271,291,273,289,278,287,279,285,281,280,284,278,284,276,287,277,289,283,291,286,294,291,296,295,299,300,301,304,304,320,305,327,306,332,307,341,306,349,303,354,301,364,301,371,297,375,292,384,291,386,302,393,324,391,333,387,328,375,329,367,329,353,330,341,331,328,336,319,338,310,341,304,341,285,341,278,343,269,344,262,346,259,346,251,349,259,349,264,349,273,349,280,349,288,349,295,349,298,354,293,356,286,354,279,352,268,352,257,351,249,350,234,351,211,352,197,354,185,353,171,351,154,348,147,342,137,339,132,330,122,327,120,314,116,304,117,293,118,284,118,281,122,275,128,265,129,257,131,244,133,239,134,228,136,221,137,214,138,209,135,201,132,192,130,184,131,175,129,170,131,159,134,157,134,160,130,170,125,176,114,176,102,173,103,172,108,171,111,163,115,156,116,149,117,142,116,136,115,129,115,124,115,120,115,115,117,113,120,109,122,102,122,100,121,95,121,89,115,87,110,82,109,84,118,89,123,93,129,100,130,108,132,110,133,110,136,107,138,105,140,95,138,86,141,79,149,77,155,81,162,90,165,97,167,99,171,109,171,107,161,111,156,113,170,115,185,118,208,117,223,121,239,128,251,133,259,136,266,139,276,143,290,148,310,151,332,155,348,156,353,153,366,149,379,147,394,146,399]

second = [156,141,165,135,169,131,176,130,187,134,191,140,191,146,186,150,179,155,175,157,168,157,163,157,159,157,158,164,159,175,159,181,157,191,154,197,153,205,153,210,152,212,147,215,146,218,143,220,132,220,125,217,119,209,116,196,115,185,114,172,114,167,112,161,109,165,107,170,99,171,97,167,89,164,81,162,77,155,81,148,87,140,96,138,105,141,110,136,111,126,113,129,118,117,128,114,137,115,146,114,155,115,158,121,157,128,156,134,157,136,156,136]

im = Image.new(‘1’, (1000,1000), 1) draw = ImageDraw.Draw(im) draw.line(zip(first[0::2], first[1::2])) draw.line(zip(second[0::2], second[1::2])) im.save(‘connect.png’)[/code]

最后图形显示是一只牛,英文不是bull就是cow,我只会这两个,分别试了一下。 http://www.pythonchallenge.com/pc/return/bull.html ,显示正确。 http://www.pythonchallenge.com/pc/return/cow.html ,提示hmm. it’s a male.

好吧,头上有角的是bull。

Level10 http://www.pythonchallenge.com/pc/return/bull.html

图片是一头公牛和一条狗,下面有谜面len(a[30]) = ?。

打开Html sourcecode,看到<area shape=“poly” 字样,又返回页面点击公牛的图片,显示超链接http://www.pythonchallenge.com/pc/return/sequence.txt 的内容, [code]a = [1, 11, 21, 1211, 111221,

len(a[30]) = ?[/code]

这道题首先不是考数列的规律,其次才是编程。规律我看不出来,只好搜了一下,应该是统计一个数连续出现的次数: [code]1 11 #因为1只有1个1 21 #因为11是两个11 1211 #因为21是1个2和1个1 111221 #1211是这样读的,1个1,1个2,两个1 312211 #三个1 + 两个2 + 一个1 13112221 #一个3 + 一个1 + 两个2 + 两个1 …………[/code]

这个问题常规思路就是用递归来解决,代码如下: [code]def gennum(numStr): outputList = [] ct = 1 numlength = len(numStr) loop = 0 while loop < numlength: if loop == numlength - 1: outputList.append(’%d%s’ % (ct,str(numStr[loop]))) ct = 1 else: if numStr[loop] == numStr[loop + 1]: ct += 1 else: outputList.append(’%d%s’ % (ct,str(numStr[loop]))) ct = 1 loop += 1 return ‘’.join(outputList)

def Challenge10(): n = 30 a = ‘1’ for loop in xrange(n+1): print ‘a[%d] = %s’ % (loop,a) print ’len(a[%d]) = %d’ % (loop,len(a)) a = gennum(a)[/code]

最终打印出:len(a[30]) = 5808 Next Level: http://www.pythonchallenge.com/pc/return/5808.html

Level11: http://www.pythonchallenge.com/pc/return/5808.html

打开是朦胧的图片,标题是odd even,HTML源码没有任何提示,看来又是图片做文章了。

[code]def Challenge11(): import Image im = Image.open(“cave.jpg”) w,h = im.size for x in range(4): for y in range(4): print im.getpixel((x,y)) print ‘============’[/code]

把第一行的像素都打印出来看看,看点都有什么特征。 (0, 20, 0) (148, 186, 111) (0, 20, 0) (145, 182, 105)

(142, 180, 105) (0, 20, 0) (158, 195, 118) (0, 22, 0)

(0, 20, 0) (148, 186, 109) (0, 20, 0) (158, 195, 118)

(139, 177, 100) (0, 21, 0) (148, 185, 108) (0, 20, 0)

从上可以发现,odd even的颜色是泾渭分明的,我们要的坐标点应该是很相似的颜色,都是(0, 2*, 0)的,其他点应该是干扰点。如果笨一点,发现color的r不为0并且g不为0的话就抹掉,但这道题提示很明显,odd与even,用(x + y) % 2来判断就可以了,代码如下: [code]def Challenge11(): import Image im = Image.open(“cave.jpg”) w,h = im.size for x in range(w): for y in range(h): if (x + y) % 2 == 1: im.putpixel((x, y), 0) im.show()[/code]

代码直接显示一张图片,有evil这几个字,所以下一关是http://www.pythonchallenge.com/pc/return/evil.html