python challenge(9-18)

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
]
 
import  matplotlib.pyplot as plt
 
plt.plot(first[ 1 :: 2 ],first[ 0 :: 2 ])
plt.plot(second[ 1 :: 2 ],second[ 0 :: 2 ])
plt.show()

def  counter(strin):
     old  =  strin[ 0 ]
     strout  =  ''
     count  =  1
     for  in  range ( 1 , len (strin)):
         if  strin[i]  = =  old:
             count  =  count + 1
         else :
             strout  =  strout  +  str (count)  +  old
             old  =  strin[i]
             count  =  1
     strout  =  strout  +  str (count)  +  old
     return  strout
     
=  [ '1' '11' '21' '1211' '111221' ]
for  in  range ( 30 ):
     last  =  a[ - 1 ]
     a.append(counter(last))
     
print  len (a[ 30 ])
规律还是在网上找的,囧。。len(a[30])的时候就应该想到字符串,不能从常规数学,而是从字符串的角度考虑。

from  PIL  import  Image
import  numpy
import  matplotlib.pyplot as plt
 
im  =  Image. open ( 'cave.jpg' ).convert( "L" )
im  =  numpy.asarray(im)
im1  =  im[:: 2 , :: 2 ]
 
plt.cla()
plt.imshow(im1)
plt.show()
题目暗示even odd,图片分开,用采样的方式。

content  =  open ( 'evil2.gfx' , 'rb' ).read()
for  in  range ( 5 ):
     =  open ( '%d.jpg'  %  i, 'wb' )
     f.write(content[i:: 5 ])
     f.close()
首先要能想到把evil1改成evil2,然后下载gfx。刚开始以为gfx是要用第三方库来做呢,原来根据图片发牌的提示把gfx分成5份写成图片。。(不过很奇怪的是,我第4张图片下半截没有显示完全。。)
evil4.html还给出了一个信息Bert is evil下关用。。我也是醉了。。

上关说Bert is evil。
import xmlrpclib
xmlrpc = xmlrpclib.ServerProxy( 'http://www.pythonchallenge.com/pc/phonebook.php' )
 
#print xmlrpc.system.listMethods()
#print xmlrpc.system.methodHelp('phone')
print xmlrpc.phone( 'Bert' )

from PIL import Image
 
l = [[i,i-1,i-1,i-2]  for  in  xrange(100,1,-2)]
l = reduce(lambda x, y:x+y,l)
direction = [[1,0],[0,1],[-1,0],[0,-1]]
 
im = Image.open( "wire.png" )
new  = Image. new ( "RGBA" ,(100,100))
 
col = -1
row = 0
position = 0
for  in  range(len(l)):
     add = direction[i%4]
     count = 0
     while (count<l[i]):  
         col = col+add[0]
         row = row+add[1]        
         print (col, row),(position, 0)
         new .putpixel((col,row),im.getpixel((position,0)))
                  
         position = position + 1
         count = count + 1
         
new .show()
走蛇形,面包和源码的注释是提示。只不过想不到二维码一样的东西可以在页面直接下载,且10000*1的。(猫的名字是uzi,以后可能还要用到)

源码注释:1.he ain't the youngest, he is the second?2. todo:buy flowers for tomarrow.
应该是猜一个人的名字(难道是美国总统?)1XX6年,闰月(右下角提示),
1xx6之间的闰年:[1016, 1036, 1056...1956, 1976, 1996].不是最小的,难道是1976年1月27日出生?
oo,还有细节要注意!!:该年的1月1日是星期四。这个又要怎么算啊。。写个万年历出来?(万年历有公式,可以计算),but这是python,应该有现成的东西可以用。
精确计算后:
[1176, 1356, 1576, 1756, 1976]
那就是1756年了
根据百度百科,1756年1月27出生的人是大音乐家莫扎特Mozart
import calendar
 
#1xx6之间的leapyear
leap = []
for  in  range(10):
     for  in  range(10):
         xx = str(i) + str(j)
         year = int( '1'  + xx +  '6' )
         if  calendar.isleap(year) and calendar.monthcalendar(year,1)[0][3]==1:
             leap.append(year)
print leap

题目let me get this straight,让我搞清楚还是让我走直线?查阅网上才是“把它弄直”即图中小红线弄直的意思。仔细观察,列对齐,即一条竖直的小红线(在哪儿都一样,不如全都移到第一列)。同一行内,有种拉线的感觉,把她拉到第一列。先试试。
im.getpixel((i,j))只得到一个值,而不是4元数组,查阅资料,才发现这个是颜色索引( http://baike.baidu.com/link?url=gmykyfOfQTfAD_71jSH-931WejnzzfQJzDhEc7a-OvTp7VNHXVa3LBzAe3pa-LN1kvLqYHRk4mQZQhQYjXjEea)。
ps查阅图中玫红色小线#ff00ff索引号为195,我这种查阅方法是不是太蠢。。
from PIL import Image
import numpy
import matplotlib.pyplot as plt
 
im = Image.open( 'mozart.gif' )
 
w = im.size[0]
h = im.size[1]
im = numpy.asarray(im)
new  = im.copy()
 
for  in  range(h):
     pos = list(im[i]).index(195)
     new [i,0:w-pos], new [i,w-pos:] = im[i,pos:],im[i,0:pos]
     
plt.cla()
plt.imshow( new )
plt.show()
我觉得我的代码复杂了,一定有什么简单的方法。。

题目tea?吃?图片是一些饼干,左下角是之前level4找链接出现过的图片,有什么关联?
之前level4有很多链接,链接有cookie?
哦~原来真的是cookie
import urllib2
import cookielib
 
cookie = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
 
 
response = opener.open(url)
for  item  in  cookie:
     print item.name,  item.value
出来,info you+should+have+followed+busynothing...
把nothing改为busynothing,信息出现。
import urllib2
import urllib
import re
import cookielib
  
cookie = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
 
info =  ''
for  in  range(400): 
     content = urllib.urlopen(url).read()
     request = urllib2.Request(url)
     yy = str(urllib2.urlopen(request).info())
     #这一步得到数据 不知是神马,但是却可以用re提取cookie里的info。
     #'X-Powered-By: PHP/5.3.3-7+squeeze19\r\n
     #Set-Cookie:info=B; expires=Fri, 25-Dec-2015 06:46:14 GMT; path=/; domain=.pythonchallenge.com\r\n
     #Content-type: text/html\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n
     #Date: Fri, 18 Dec 2015 06:46:14 GMT\r\n
     #Server: lighttpd/1.4.28\r\n'
 
     info = info + re.findall( 'info=(.{0,4});' ,yy)[0]   #{0,4}最小最多匹配个数
     nextnum = re.findall(r '(\d+)' ,content)
     if  nextnum==[]:
         break
     url = url.split( '=' )[0]+ '=' +nextnum[-1]
print info 
循环获取链接出现的cookie.
但不知道是网络不稳定还是怎么,上面这段程序都只能随机跑一段。。
因为跑不完,只能在网上看最后info是什么。下面用网上跑出来的info接着做。
import bz2
info =  'BZh91AY&SY\x94:\xe2I\x00\x00!\x19\x80P\x81\x11\x00\xafg\x9e\xa0 \x00hE=M\xb5#\xd0\xd4\xd1\xe2\x8d\x06\xa9\xfa&S\xd4\xd3!\xa1\xeai7h\x9b\x9a+\xbf`"\xc5WX\xe1\xadL\x80\xe8V<\xc6\xa8\xdbH&32\x18\xa8x\x01\x08!\x8dS\x0b\xc8\xaf\x96KO\xca2\xb0\xf1\xbd\x1du\xa0\x86\x05\x92s\xb0\x92\xc4Bc\xf1w$S\x85\t\tC\xae$\x90'
print bz2.decompress(info)
结果:is it the 26th already? call his father and inform him that "the flowers are on their way". he'll understand.
给他的爸爸打电话,莫扎特的爸爸?是谁? 列奥波尔德·莫扎特(Leopold Mozart  )
参照之前的一个题
import xmlrpclib
xmlrpc = xmlrpclib.ServerProxy( 'http://www.pythonchallenge.com/pc/phonebook.php' )
print xmlrpc.phone( 'Leopold' )
得:555-VIOLIN.  http://www.pythonchallenge.com/pc/stuff/violin.php 细看照片,上面没有18,所以这关还没过。。
一个人像,查看源代码,‘ it's me. what do you want?’再看照片名字,‘leopold.jpg’,莫扎特他老爹。可是这道题要干什么呢?
from urllib2 import Request, urlopen
from urllib import quote_plus
  
info =  'the flowers are on their way'
  
req = Request( url, headers={ 'Cookie' 'info='  + quote_plus(info)} )
print urlopen(req).read()
查阅网上,代码如上。这道题考网络通信方面的,不熟悉,所以做起来比较吃力。
结果:oh well, don't you dare to forget the balloons

两张图片,一张亮一点,一张暗一点。提示: it is more obvious that what you might think。
亮度不一样。亮度,brightness,  http://www.pythonchallenge.com/pc/return/brightness.html
查看源文件: maybe consider deltas.gz
import difflib  #序列(特别是文本行)比较
 
data = gzip.open( 'deltas.gz' 'r' ).read()
data = data.splitlines()
left = []
right = []
i = 0
for  line  in  data:
     i = i+1
     print i
     left.append(line[0:53])
     right.append(line[56:]) 
     
diff = list(difflib.ndiff(left,right))
#比较的结果有三种,-(仅在片段1存在)、+(仅在片段2中存在)、' '(片段1和2都存在)
minus_data =  ''
add_data =  ''
space_data =  ''
for  line  in  diff:
     s = line[0]
     t =  ''
     for  in  line[2:].split():
         t = t + chr(int(b,16))   #单纯的字符'89'转化成'\x89' 16进制的字符数
         
     if  line[0] ==  '-' :
         minus_data += t
     elif line[0] ==  '+' :
         add_data += t
     elif line[0] ==  ' ' :
         space_data += t
         
open( 'add.png' , 'wb' ).write(add_data)
open( 'minus.png' , 'wb' ).write(minus_data)
open( 'space.png' , 'wb' ).write(space_data)  
熟悉了diff的用法,也见识了.png的这种写法,准确来说,这种写法之前也见过,发牌分5堆那题。
至此,调整好心态,不是纯来做题的,也是来学习知识的,python的各种库一起其他好多东西。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值