The first Python Programming challenge on the Internet (end)

Time:2020-10-25

Date of establishment: March 28, 2020

Update Date: April 22, 2020 (end)

Personal collection Tool.py

website:http://www.pythonchallenge.com/

Note: please quote or change this article at will, just mark the source and the author. The author does not guarantee that the content is absolutely correct. Please be responsible for any consequences

Title: the first Python Programming challenge on the web

Find a website to challenge your understanding of Python and your IQ. The following is a detailed explanation of each problem. You will not solve all the problems at once, and supplement the content periodically

(the content of the question is mainly in English)

Level 0http://www.pythonchallenge.com/pc/def/0.ht…

The first Python Programming challenge on the Internet (end)

Hint: try to change the URL address.

Tip: try changing the URL address

[explanation]

  1. Because this is the 0 level, to find the first level, so change the 0 in the URL to 1

    http://www.pythonchallenge.com/pc/def/1.ht…

    2**38 is much much larger.

    2 * * 38 is very, very large
  2. Let’s figure out how big 2 * * 38 is
    >>> print(2**38)
    274877906944
  3. Put this number into the URL, the results into the first level

    http://www.pythonchallenge.com/pc/def/2748…

    Moreover, the URL is changed to map, indicating that the map may have holes

Level 1http://www.pythonchallenge.com/pc/def/map….

The first Python Programming challenge on the Internet (end)

everybody thinks twice before solving this.

g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr’q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.

[solution] there is a paragraph at the bottom of the graph that looks like garbled code. In the figure, converting K, O, e into m, Q, G is a transcoding problem

  1. The intuitive idea, of course, is to convert K, O, e into m, Q, G in the chaotic content, and the result is still garbled
text = ("g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc"
        "dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcv"
        "r gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnj"
        "w ml rfc spj.")
text = text.replace('k', 'm').replace('o', 'q').replace('e', 'g')
print(text)
"""
g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr ammnsrcpq ypcdmp. bmglg gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmlg. sqglg qrpglg.myicrpylq() gq pcammmclbcb. lmu ynnjw ml rfc spj.
"""
  1. Observe that each conversion moves the letter 2 bits backward. Suppose y, Z moves a, B. here it is lowercase, regardless of upper case
text = ("g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc"
        "dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcv"
        "r gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnj"
        "w ml rfc spj.")#Use the maketrans and translate of the string to make the conversion= ''.join([chr(ord('a')+i) for i in range(26)]) # abcd...xyz
table2 = table1[2:]+table1[:2]                         # cdef...zab
trans = table1.maketrans(table1, table2)
result = text.translate(trans)
print(result)
"""
i hope you didnt translate it by hand. thats what computers arefor. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
"""
  1. Well, see the normal English sentence, but how to put the website? Change to maketrans?

    http://www.pythonchallenge.com/pc/def/make…

    that’s a handy little function. isn’t it?

    It’s still wrong. I didn’t enter the second level
  2. By the way, the map on the web site may have holes, try to convert it
text = "map"
...

"""
ocr
"""
  1. Changed the URL to OCR, and it really entered the second level

Level 2http://www.pythonchallenge.com/pc/def/ocr….

The first Python Programming challenge on the Internet (end)

recognize the characters. maybe they are in the book,

but MAYBE they are in the page source.

[explanation] the words in the book are too vague to be seen clearly, so the answer should be in page source, which means that in the source code, right-click to view the original source code of the web page

  1. Look at the source code

    There is a special place for us to find the rare words in that long string
<!--
find rare characters in the mess below:
-->

<!--
%%[email protected]_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[([email protected]%+%$*^@$^!+] !&_#)_*}{}}!}_]$[%}@[{[email protected]#_^{*
@##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$] #{*+^((@^@}$[**$&^{[email protected]#$%)[email protected](&
...
}!)$]&($)@](+(#{$)_%^%_^^#][{*[)%}+[##(##^{$}^]#&( &*{)%)&][&{]&#]}[[^^&[!#}${@_( |
#@}&$[[%]_&$+)$!%{(}$^$}* |
-->
  1. In order not to copy a large number of characters, open the web page capture, this starts the crawler Because it’s simple, we don’t need BS4 or other packages to parse HTML. We set up a dictionary to record the number of times all words appear
from urllib import request

url = "http://www.pythonchallenge.com/pc/def/ocr.html"
with request.urlopen(url) as response:
    data = response.read()

html = data.decode('utf-8')
start_string = "<!--\n"
length = len(start_string)
stop_string = "-->\n"#There are two comments,We're looking for the one in the back,So use rfind,No find.
start = html.rfind(start_string)
stop = html.rfind(stop_string)
text = html[start+length:stop].replace('\n', '')

chars = {}
for char in text:
    chars[char] = chars[char] + 1 if char in chars else 1
avg = sum(chars.values())/len(chars)
result = ''.join([char for char in chars if chars[char]<avg])
print(result)
"""
equality
"""
  1. Change the URL to equality, well, as expected, see the third level
  2. We can also use the regular form here, but this is a known result of A-Z each time
import re
print(''.join(re.findall('[a-z]', text)))
"""
equality
"""

< continue next time >

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint


Jason Yang