Python Challenge Customs Code and tips (9-16)

Source: Internet
Author: User
Tags floor division image processing library

Question Nineth

Problem analysis

The picture is the same as the previous question. There are strange dots of dots. This problem should be examined in the same way as the previous question is also an image analysis class.

View source code.

You can download good.jpg on the page. Then prompt first+second=?
Then first and second each correspond to a series of numbers. Then it should be two numbers together, representing a pixel point.

If we put black dots on the original picture, we don't see any change. So we create a new white-background image, which is then smeared with black dots.

Examining Knowledge points

Python-image basic image processing operations (likes)
http://www.aichengxu.com/view/39904

Image module for the introduction of the Python Graphics image processing library
Http://onlypython.group.iteye.com/group/wiki/1372-python-graphics-image-processing-library-introduced-the-image-module

Python Imaging Library (PIL) Download
http://www.pythonware.com/products/pil/

Code and results
Import Re, Imagefile=Open(' d:/python/good.html ') message = Re.findall (' (<!--[^-]+-->) ',file.Read(), Re. S) [1]file.Close() First= Re.findall (' (/d+) ', Re.findall (' First: (. +) Second ', Message,re. S) [0],re. SSecond= Re.findall (' (/d+) ', Re.findall (' Second: (. +) > ', Message,re. S) [0],re. S) All = First+Secondim = Image.Open(' d:/python/good.jpg ') im2 = Image.New(Im.mode, Im.size) forXinchRange0,Len(All),2): Im2.putpixel ((int (all[x)), int (all[x+1])),(255,255,255,255)) Im2.show ()

Show a cow, then it's bull.

Enter http://www.pythonchallenge.com/pc/return/bull.html, i.e. customs clearance

Question Tenth

Problem analysis

See Len (a[30]) on the Web page =? is to let us calculate the length of the element labeled 30 in the A array

But by convention. View Source

To be honest, there is no regularity in this string. And according to Len (a[30]) =? This hint should be given an array to let us count.

At this time found href= "Sequence.txt" very suspicious, after clicking

So let's calculate the Len (a[30]) of this array = how much

I don't see the rules. After Baidu learned

11-Indicates that the previous number "1" is a 1;
21-Indicates that the previous number "11" is composed of 2 1;
1211-Indicates that the previous number "21" is composed of a 2, a 1;
111221-that is 11 12 21, indicating that the previous number "1211" is followed by a 1, a 2,
2 of 1 components;

That is, each number describes the composition of the preceding number

Examining Knowledge points

Find the rules.

    1. Division in Python
      http://blog.csdn.net/sicofield/article/details/8613877

      Floor Division (divisible): Starting from Python2.2, an operator//is added to perform the floor division://Divide regardless of the numeric type of the operand, the fractional part is always removed, returning the nearest number in the sequence of numbers that is smaller than the true quotient.

Code and results
strings = [' 1 ',' One ']elements of #计算1-30 forIinchRange1, to):#计数器重置j =0temp ="'          #当计数器j小于当前元素的长度时 (that is, when the length of the current element has not been calculated)         whileJ <Len(Strings[i]): Count =1                #当计数器j小于前一个元素的长度时且strings [i][j]==strings[i][j+1]                 whilej< (Len(Strings[i])-1) and(strings[i][j]==strings[i][j+1]): j = j +1Count = Count +1temp ='%s%d%c '% (Temp,count,strings[i][j]) j = j +1Strings.append (temp) print (Len(strings[ -]))

The result is: 5808

Input: http://www.pythonchallenge.com/pc/return/5808.html, Customs clearance

Question 11th

Problem analysis

What a picture like a mosaic is. Estimates are related to image processing.

View the source code.

Click

Examining Knowledge points

Image analysis related (similar to question eighth, Nineth)

It is possible to be related to the parity of image coordinates, if we create a new image according to the specifications of the original image, and on the image only in the coordinates of the odd value or even the point on the original image, found that all is a dark piece; so we try to deal with half the size of the original piece again.

Python-image basic image processing operations (likes)
http://www.aichengxu.com/view/39904

Image module for the introduction of the Python Graphics image processing library
Http://onlypython.group.iteye.com/group/wiki/1372-python-graphics-image-processing-library-introduced-the-image-module

Python Imaging Library (PIL) Download
http://www.pythonware.com/products/pil/

Code and results

Image analysis, I have always been not very good at. This is Baidu's other people's source code.

Original
http://blog.csdn.net/billstone/article/details/4546725

Import Image im = Image.open ("Cave.jpg") odd = Image.new (Im.mode, (IM.size[0]/2, im.size[1]/2)) even = Image.new (Im.mode, (IM.size[0]/2, im.size[1]/2)) forXinchRange1, im.size[0],2): forYinchRange1, im.size[1],2): Odd.putpixel (((x1)/2, (Y1)/2), Im.getpixel ((x, y))) forXinchRange1, im.size[0],2): forYinchRange1, im.size[1],2): Even.putpixel ((x/2, y/2), Im.getpixel ((x, y))) Odd.save (' odd.jpg ') Even.save (' even.jpg ')

Run the code, look at Odd.jpg and Even.jpg, find the two graphs are almost the same, through the inverse color processing, we found in the upper right corner of the word Evil

Enter http://www.pythonchallenge.com/pc/return/evil.html, i.e. customs clearance

Question 12th

Problem analysis

The page does not have the text information, looks the picture, seems to want to divide the card.

View Source

Src= "Evil1.jpg" Only this looks strange, click, or show the licensing picture

Consider that the picture shows a licensing, change the address to Evil2.jpg
Http://www.pythonchallenge.com/pc/return/evil2.jpg

The tip says: Not jpg, it's gfx. Then change the suffix name to GFX so you can get a binary file. Download it to your computer.

Continue testing Evil3.jpg

Try Evil4.jpg.

It's not responding. It seems that the key is evil2.jpg.

The data in the file is then distributed to five new files in a licensing manner, Distribution is as follows: The first byte of the EVIL.GFX to the first file, the second byte to the second file, the third byte to the third file, the fourth byte to the fourth file, the fifth byte to the fifth file, sixth bytes to the first file, seventh bytes to the second file ...

Examining Knowledge points

Scope resolution operator (::)
http://blog.csdn.net/chamtianjiao/article/details/6406751

Code and results

In notepad++, edit the exc12.py

#读取文件里的信息open(‘evil2.gfx‘,‘rb‘)  content = f.read()  f.close()  #新建一个图片,将文件中的字符开始平均分发forin range(5):      open(‘%d.jpg‘‘wb‘)      f.write(content[i::5])      f.close() print("done!please check your file")

There are new files in the folder.

Click to see in the order. Separately is dis, pro, port,ional, and the last one was crossed out, whatever it

The combination of English words is disproportional.

Therefore, enter http://www.pythonchallenge.com/pc/return/disproportional.html, that is, customs clearance

Question 13th

Problem analysis

Look at the picture text tip is to call the devil?

View Source

Found at this time
Area shape= "Circle" coords= "326,177,45" href= ". /phonebook.php "very suspicious.

Phonebook is the phone book, since you have to call the devil, you must find the Devil's phone number in the phone book ~

Click phonebook.php

It should be about XML.

Baidu later learned that is to investigate Xmlrpclib module

Examining Knowledge points
    1. Python uses Xmlrpc instances to explain
      Http://www.jb51.net/article/44515.htm
Code and results
首先,导入xmlrpclib,然后连接phonebook.php,接着使用listMethods方法查看了一下可使用的方法,发现有一个叫phone方法,再然后使用methodHelp方法查看了一下phone方法的帮助,于是乎这题就解出来了。
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‘)  

And finally get Bert's phone--555-italy

Enter http://www.pythonchallenge.com/pc/return/italy.html, i.e. customs clearance

Question 14th

Problem analysis

It shows a lap of bread, and there's a picture under it that's blocking something.

View Source

This source seems to suggest a lot of places ~

Walk around: Walk around

–remember:100*100 = (100+99+99+98) + (... : Tell us to remember the formula.

Two photos. Click "Italy.jpg, or the ugly bread, there is nothing to pay attention to

Click Wire.png,

I don't feel a clue. But it's definitely about the picture processing.

Examining Knowledge points

Image module

Code and results

This is not done, put a link to make out the person

http://blog.csdn.net/kosl90/article/details/7341181

L = [[I, I-1I1I2] forIinchXrange -,1, -2)] L = reduce (lambda x, Y:x+y, L)# print L, Len (l)Import Image org = Image.open (' Level14.d/wire.png ') Org_data = List (Org.getdata ()) res = Image.New(Org.mode, ( -, -)) Res_data = Res.load ()# (0,0)#---->x#    | # VYdire = [(1,0),# > (x+1, y) right(0,1),# V (x, y+1) down(-1,0),# < (x-1, y) left(0, -1),# ^ (x, y-1) up]# initv =0Org_index =0Res_pos = (-1,0) forTimesinchL forIinchXrange (Times):# pos'll out of index if reset position after setting colorRes_pos = tuple (map (lambda x, y:x + y, Res_pos, dire[v]))# (Res_pos[0] + dire[v][0], res_pos[1] + dire[v][1])        # f = open (' Level14.d/log.log ', ' a ')        # Print >> F, POS        # f.close ()Res_data[res_pos] = Org_data[org_index] Org_index + =1v = (v +1) %4  # J + 1 if j! = 4 Else 0Res.save (' Level14.d/res.png ')

Finally got a cat image, the cat called Uzi

Enter http://www.pythonchallenge.com/pc/return/uzi.html, i.e. customs clearance

Question 15th

Problem analysis

There must be a special meaning in the calendar that circled number 26th.

View Source

Let's guess who this person is.

said he ain ' t the youngest, he is the the second. He is the second-youngest (in the family rankings, otherwise than who?) )

Buy Flowers for Tomorrow: That is, number 27th, maybe a funeral or a birthday, need to buy flowers for this day

Well.. It seems that the question does not need Python Baidu, or people familiar with the European celebrity deeds can easily guess

So what is the purpose of this study?

Think carefully, we only know a number 27th, only know the age, if we are not very familiar with European history (for example, I), then we need to narrow the scope, after all, it is now 2016 years, do not know in which year he was born.

How to narrow the range? From the calendar, 27th is Tuesday, this can be used to narrow the scope, then there is no other conditions?

Picture in the lower right corner. In a very blurry picture, the number of squares can be found in February only 29 days, so is a leap year.

When we need to find a leap year, January 27 is the date of Tuesday. Then Baidu check that person's message is the family's second son on the line ~

Date processing, select the Calendar and datetime module for Python

Examining Knowledge points
    1. Python time module How to use datetime, date, and calendar
      Http://www.jb51.net/article/77971.htm

    2. DateTime module
      Python's datetime module features detailed

Code and results

In nodepad++, edit the exc15.py

from calendar import isleap  fromdate  1  #从1800年到2000年foryearin range(1800,2000):    date(year127)      #是闰年并且1月的27号是星期一    if isleap(yearand t.weekday() == TUESDAY:          print (t.isoformat())  

Baidu these dates ~

It's obviously Mozat.

Enter http://www.pythonchallenge.com/pc/return/mozart.html, i.e. customs clearance

Question 16th

Problem analysis

Must be a picture processing, view the source code

Note This word let me get this straight

With a pink dot as the benchmark, the other pixels are lined up in a straight line and should be able to produce results.

Examining Knowledge points

Image module

Code and results
Import Imageim = Image.Open("Mozart.gif") forYinchRange (im.size[1]):#获得像素点     Line=[im.getpixel ((x, y)) forXinchRange (im.size[0])] Idx= Line. Index (195) Line= Line[idx:]+ Line[: IDX]#重新排列像素点[Im.putpixel (x, y), Line[x]) forXinchRangeLen( Line))]im.show ()

Results:

Enter http://www.pythonchallenge.com/pc/return/romance.html, i.e. customs clearance

Python Challenge Customs Code and tips (9-16)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.