[Python] [pythonchallenge] [TBC] the ancient python online challenge, interesting (C0-C4), challenge

Source: Internet
Author: User

[Python] [pythonchallenge] [TBC] the ancient python online challenge, interesting (C0-C4), challenge

Expected reading time: 15 minutes

Background: It was discovered by accident when searching materials. Each level covers many knowledge points.

Python: 3.0

Talking is cheap, show me the code

Home: http://www.pythonchallenge.com/

Warm-up: Click Start Challenge to enter the warm-up level

Http://www.pythonchallenge.com/pc/def/0.html

1. Enter 238.html

2. Get a new prompt: No... the 38 is a little bit above the 2...

3. Review the picture and enter the http://www.pythonchallenge.com/pc/def/274877906944.html

1 bogon:~ hbai$ python2 Python 2.7.6 (default, Sep  9 2014, 15:04:36) 3 [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin4 Type "help", "copyright", "credits" or "license" for more information.5 >>> 2**386 2748779069447 >>> 

4. Congratulations! We officially entered level 1

First off: http://www.pythonchallenge.com/pc/def/map.html

Homepage prompt: What about making trans? According to the translation rules, # k-> m o-> q e> G shifts two digits after each character.

1 # coding = UTF-8 2 3 # In py2.7 need following import 4 # from string import maketrans 5 6 7 # page: http://www.pythonchallenge.com/pc/def/map.html 8 # Try 1: Replace the specified 3 characters, 9 # k-> m o-> q e> G10 str = "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. kyicrpyscsi () gq pcamkkclbcb. lmu ynnjw ml rfc spj. "11 12 print (str. replace ('k', 'M '). replace ('O', 'q '). replace ('E', 'G') 13 14 # Use transtab to translate 15 intab = "abcdefghijklmnopqrstuvwxyz" 16 outtab = "cdefghijklmnopqrstuvwxyzab" 17 trantab = str. maketrans (intab, outtab) 18 19 print (str. translate (trantab) 20 21 # http://www.pythonchallenge.com/pc/def/map.html22 print ('HTTP: // www.pythonchallenge.com/pc/def/'+ 'map '. translate (trantab) + '.html ')

Use maketrans and translate for translation.

 

Second off: http://www.pythonchallenge.com/pc/def/ocr.html

View the webpage source code as prompted

<!--find rare characters in the mess below:--><!--%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*@##&{# 
。。。。
-->

Purpose: Find the minimum number of characters
Copy the string to the local storage,It runs slowly, but eventuallyExpected answer: equality
def check_CharFrequence(str):    decode = []    for i in str:        if str.count(i) < 5:            decode.append(i)    print(''.join(decode))    #print sorted(char_freq.items(),key = lambda x: (x[1]))   #    aeilqutywith open('C2_info.txt') as f:    #My method: it's very very not good, because of N^N complex    check_CharFrequence(f.read())    print(f.read())

Further Thinking: Please refer to the standard answer page http://www.pythonchallenge.com/pcc/def/equality.html

 

Third off: http://www.pythonchallenge.com/pc/def/equality.html

According to the prompt: One small letter, surroundedEXACTLYThree big bodyguards on each of its sides.

Write regular expression for the first time: # pattern = re. compile ('[A-Z] {3} ([a-z]) [A-Z] {3}', re. s). Save the source code and run it.

Later I referred to the answer and found that I should modify it as follows:

#coding=utf-8import re#page= http://www.pythonchallenge.com/pc/def/equality.html#Previous std answer: http://www.pythonchallenge.com/pcc/def/equality.html#Current page is http://www.pythonchallenge.com/pcc/def/linkedlist.phpsampleStr='kAewtloYgcFQaJNhHVGxXDiQmzjfcpYbzxlWrVcqsmUbCunkfxZWDZjUZMiGqhRRiUvGmYmvnJIHEmbT \MUKLECKdCthezSYBpIElRnZugFAxDRtQPpyeCBgBfaRVvvguRXLvkAdLOeCKxsDUvBBCwdpMMWmuELeG \ENihrpCLhujoBqPRDPvfzcwadMMMbkmkzCCzoTPfbRlzBqMblmxTxNniNoCufprWXxgHZpldkoLCrHJq \vYuyJFCZtqXLhWiYzOXeglkzhVJIWmeUySGuFVmLTCyMshQtvZpPwuIbOHNoBauwvuJYCmqznOBgByPw''''Hint: One small letter, surrounded by EXACTLY three big bodyguards on each of its sides. '''#My method is NOT correct#pattern = re.compile('[A-Z]{3}([a-z])[A-Z]{3}',re.S)#Following is CORRECTpattern = re.compile('[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]')#print pattern.findall(sampleStr)with open('C3_info.txt') as f:    codeList = pattern.findall(f.read())    print(''.join(codeList))

Fourth off: http://www.pythonchallenge.com/pc/def/linkedlist.php

The old rule is as follows:

<!-- urllib may help. DON'T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough. --><center><a href="linkedlist.php?nothing=12345"></a>

Trying to open the page http://www.pythonchallenge.com/pc/def/linkedlist.php? Nothing = 12345

Interesting. You need to climb to Layer 3 in order to win.

 1 # coding=utf-8 2  3 # page = http://www.pythonchallenge.com/pc/def/linkedlist.php 4  5 page = 'http://www.pythonchallenge.com/pc/def/linkedlist.php' 6 loopMainpage = 'http://www.pythonchallenge.com/pc/def/' 7 firstpage = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' 8  9 from urllib import request10 import time11 import re12 13 14 def looppage(page,num):15     response = request.urlopen(page+str(num))16     html = response.read()17     print(html.decode("utf-8"))18     pattern = re.compile('and the next nothing is (\d{1,10}).*?')19     target = re.findall(pattern,html.decode("utf-8"))20     print(page + target[0])21     return target[0]22 23 24 import random25 return_num = looppage(firstpage,'82682')26 i = 027 while i < 300:28     print('Index %s:' % i)29     return_num = looppage(firstpage,return_num)30     time.sleep(random.randint(5,10))31     i +=1

Pitfalls encountered during crawling:

1. Sometimes the page does not respond, so the random wait time is added (in fact, the anonymous proxy should be used for random crawling, But I haven't finished that method yet ...)

2. One Layer prompts you to divide the current number by two. Therefore, you must manually enter the number and continue crawling.

Congratulations! peak.html

Index 107:
and the next nothing is 52899
http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=52899
Index 108:
and the next nothing is 66831
http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831
Index 109:
peak.html
Traceback (most recent call last):
  File "/Users/hbai/PycharmProjects/interview/Py_study/pythonchallenge/C4.py", line 57, in <module>
    return_num = looppage(firstpage,return_num)
  File "/Users/hbai/PycharmProjects/interview/Py_study/pythonchallenge/C4.py", line 32, in looppage
    print(page + target[0])
IndexError: list index out of range

Process finished with exit code 1

Fifth off: http://www.pythonchallenge.com/pc/def/peak.html

I am prompted on the Internet that I should use the pickle library for operations. I tried it and it didn't work. Please try again later.

To Be Continued...

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.