[Python][pythonchallenge][TBC]古老的python在线挑战赛,很有意思 (C0-C4)
预计阅读时间:15分钟
背景:搜索资料时候偶然发现的,很有意思,每一关都覆盖了很多知识点
Python版本:3.0
Talking is cheap,show me the code
主页: http://www.pythonchallenge.com/
热身关: 点击开始挑战,进入热身关卡
http://www.pythonchallenge.com/pc/def/0.html
1.根据提示,输入238.html
2.得到新提示: No... the 38 is a little bit above the 2...
3. 重新观察图片,输入 http://www.pythonchallenge.com/pc/def/274877906944.html
bogon:~ hbai$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 2**38
274877906944
>>>
4. 恭喜,正式进入第一关
第一关:http://www.pythonchallenge.com/pc/def/map.html
主页提示: What about making trans? 根据翻译规律,#k -> M O->Q E > G 每个字符都后移2位
#coding=utf-8 #In py2.7 need following import
#from string import maketrans #page: http://www.pythonchallenge.com/pc/def/map.html
#尝试1: 替换指定的3个字符,发现句子还是看不懂
#k -> M O->Q E > G
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.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj." print(str.replace('k','m').replace('o','q').replace('e','g')) #根据提示,使用transtab翻译
intab = "abcdefghijklmnopqrstuvwxyz"
outtab = "cdefghijklmnopqrstuvwxyzab"
trantab = str.maketrans(intab, outtab) print(str.translate(trantab)) #http://www.pythonchallenge.com/pc/def/map.html
print('http://www.pythonchallenge.com/pc/def/'+ 'map'.translate(trantab) + '.html')
使用maketrans、translate进行翻译,过关
第二关:http://www.pythonchallenge.com/pc/def/ocr.html
根据提示,查看网页源代码
<!--
find rare characters in the mess below:
--> <!--
%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*
@##&{#
。。。。
--> 目标:找到出现最少的字符
将字符串copy到本地保存,运行很慢,但是最终得到答案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])) # aeilquty with 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())
进一步的思考: 请查看标准答案页面 http://www.pythonchallenge.com/pcc/def/equality.html
第三关:http://www.pythonchallenge.com/pc/def/equality.html
根据提示: One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.
第一次写出正则: #pattern = re.compile('[A-Z]{3}([a-z])[A-Z]{3}',re.S) ,保存源码后运行但是发现还是不对
后来参考答案,发现应该修改如下
#coding=utf-8
import 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.php sampleStr='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 CORRECT
pattern = 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))
第四关: http://www.pythonchallenge.com/pc/def/linkedlist.php
老规矩,查看源码发现提示如下:
<!-- 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"><img src="chainsaw.jpg" border="0"/></a>
尝试打开页面http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

有意思,需要依次爬到第300层就胜利了
# coding=utf-8 # page = http://www.pythonchallenge.com/pc/def/linkedlist.php page = 'http://www.pythonchallenge.com/pc/def/linkedlist.php'
loopMainpage = 'http://www.pythonchallenge.com/pc/def/'
firstpage = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' from urllib import request
import time
import re def looppage(page,num):
response = request.urlopen(page+str(num))
html = response.read()
print(html.decode("utf-8"))
pattern = re.compile('and the next nothing is (\d{1,10}).*?')
target = re.findall(pattern,html.decode("utf-8"))
print(page + target[0])
return target[0] import random
return_num = looppage(firstpage,'')
i = 0
while i < 300:
print('Index %s:' % i)
return_num = looppage(firstpage,return_num)
time.sleep(random.randint(5,10))
i +=1
爬的过程中遇到的坑:
1. 页面有时候就不响应了,因此添加了随机等待时间 (其实应该用匿名代理随机爬最保险,但是那个方法我还没写完。。。)
2. 有一层是提示要当前数字除以二,因此要手工输入一次再继续爬
爬到最后,恭喜你: 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 rangeProcess finished with exit code 1
第五关:http://www.pythonchallenge.com/pc/def/peak.html
网上提示应该使用pickle库进行操作,试了一下没成功,有空再继续吧
To Be Continued...
[Python][pythonchallenge][TBC]古老的python在线挑战赛,很有意思 (C0-C4)的更多相关文章
- python之FTP程序(支持多用户在线)
转发注明出处:http://www.cnblogs.com/0zcl/p/6259128.html 一.需求 1. 用户加密认证 (完成)2. 允许同时多用户登录 (完成)3. 每个用户有自己的家目录 ...
- Python操作Mysql实例代码教程在线版(查询手册)_python
实例1.取得MYSQL的版本 在windows环境下安装mysql模块用于python开发 MySQL-python Windows下EXE安装文件下载 复制代码 代码如下: # -*- coding ...
- 从零开始学Python第0周:Python基本介绍(部分内容来源于网络)
Python入门介绍 一,Python的基本介绍 (1)概要 Python是一种解释型,面向对象,动态数据类型的高级程序设计语言.常被广泛用于处理系统管理任务和web编程.现如今Python已经成为了 ...
- python公司面试题集锦 python面试题大全
问题一:以下的代码的输出将是什么? 说出你的答案并解释. class Parent(object): x = 1 class Child1(Parent): pass class Child2(Par ...
- python学习之路-1 python简介及安装方法
python简介 一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年发明,第一个公开发行版发行于1991年. 目前最新版本为3.5.1,发布于2015年12月07日 ...
- Python学习笔记1-搭建Python环境 和 Python Hello World!
一.搭建Python开发环境 1.选择开发工具 首先要寻找一个Python的开发工具,Python的开发工具有很多,有pyCharm .Eclipse.Visual studio等等 ,使用最多的还是 ...
- python经典书籍推荐:Python核心编程
作者:熊猫烧香 链接:www.pythonheidong.com/blog/article/27/ 来源:python黑洞网 对<Python核心编程>的褒奖 “ The long-awa ...
- Python学习(二)Python 简介
Python 简介 官方指南及文档 Python2.7官方指南(中文版):http://pan.baidu.com/s/1dDm18xr Python3.4官方指南(中文版):http://pan.b ...
- 『Python基础-1 』 编程语言Python的基础背景知识
#『Python基础-1 』 编程语言Python的基础背景知识 目录: 1.编程语言 1.1 什么是编程语言 1.2 编程语言的种类 1.3 常见的编程语言 1.4 编译型语言和解释型语言的对比 2 ...
随机推荐
- PHP和MySQL.Web开发(原书第4版)学习盲点笔记
1.浏览器输出中文乱码解决: <?php header("Content-type: text/html; charset=utf-8"); ?> 相当于html中的: ...
- 偶尔在网上看到的,相对比较好的c#端订单号生成规则
偶尔在网上看到的,相对比较好的c#端订单号生成规则 public class BillNumberBuilder{ private static object locker = new obj ...
- 渡鸦币(Raven)钱包交叉编译详解
1 环境准备 1.1 准备Ubuntu 准备虚拟机或物理机,操作系统为Ubuntu 16.04 1.2 安装Mingw sudo apt-get install g++-mingw-w64-i686 ...
- CVE-2019-0708 RDP MSF漏洞利用
CVE-2019-0708 RDP MSF漏洞复现 漏洞环境 使用 VMware 安装Windows7 X64 模拟受害机 Windows7 X64下载链接:链接: https://pan.baidu ...
- Information Cartography
作者:Dafna Shahaf 会议:ACM 2015. 研究大背景:自动化地从很大数据集中提取结构化的知识变得越来越难.在本篇文章中,我们将探索我们在文献中(25,26,27)中创立的方法来自 ...
- 乐字节Java学习03-path环境变量
1. path环境变量的作用 保证javac命令可以在任意目录下运行. 2. path配置的两种方案: 方法 一如下: ①点击计算机->右键->属性 ②高级系统设置 ③高级—>环境变 ...
- Linux(CentOS 7)下安装postgres
事情背景:需要在Linux上安装postgres数据库,但安装目录想直接指定,所以想通过源码编译安装pg 首先下载源码安装包.源码下载地址:https://github.com/postgres/po ...
- [DEBUG] ubuntu mysql root@localhost改了密码还是进不去ERROR 1698 (28000)
之前用skip-grant-tables的方法免密进入Mysql,修改了root的密码, 当时重启服务后是可以用密码进入Mysql的.结果昨天突然又进不去了:) 所以更换方法,特此记录. ====== ...
- 希尔排序——C语言
希尔排序 希尔排序是插入排序的一种,又称“缩小增量排序”,希尔排序是直接插入排序算法的一种更高效的改进版本,关于插入排序可以看下这篇随笔:插入排序——C语言 (图片来源:https://www.cnb ...
- C++ std::string 在一个字符串前插入一个字符串几种方式
目录 1.直接使用字符串相加 2.使用insert函数 比较:通过Quick C++ Benchmarks 可得到结果 1.直接使用字符串相加 std::string a = "hello& ...