python challenge 待续中

网址:http://www.pythonchallenge.com/
解答好文:http://story.iteye.com/blog/730466

0:2^38

1 reduce(lambda x,y:x*y,[2]*38)   #输入时不要输入L,只是表示类型为Long

1:位移两位

 1 import string
 2  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."
 3  transfun=string.maketrans(‘abcdefghijklmnopqrstuvwxyz‘,‘cdefghijklmnopqrstuvwxyzab‘)
 4  print str.translate(transfun)
 5  -->
 6     i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that‘s why this text is so long.
 7     using string.maketrans() is recommended. now apply on the url.
 8
 9  *ord(‘A‘)可转化为ASCII码,chr(65)可转化为字符
10   但是注意最后两位y与Z不能用ASCII+2而是对应到a,b

2:page source即是源代码里面,写的有找最少
 将那些字符复制到同路径名字为data的文件夹,采用伪木桶算法,这样每次操作都是O(1)

 1 a={}
 2 eleL=set(list(‘equality#)^)&!_+]!*@&^}@[@%]()%+$&[([email protected]%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{[email protected]#_^{*@##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{[email protected]#$%)[email protected](&+^!{%_$&@^!}$_${)$_#)!({@!)(^}!*^&!$%_&&}&_#&@{)]{+)%*{&*%*&@%$+]!*__(#!*){%&@++‘))
 3 for i in eleL:
 4     a[i] = 0
 5
 6 with open(‘data‘,‘r‘) as f:
 7     str=‘‘
 8     for line in f.readlines():        #最好一行一行的处理,一起读出来太大容易卡电脑
 9         line = list(line.strip())   #strip去掉换行符
10         for i in line:
11             a[i]+=1
12     print(a)
13 最后发现有几个字母都是只出现了一次:equality
14 **其实有个bug,equality这个词通过写是报Keyerror即可看出来了!!!第二行我是复制了三行进去再用set去重,报keyerror我才添加equality进去的

3:One small letter, surrounded by EXACTLY three big bodyguards on each of its sides:
找到一个周围被三个大写字母包围的小写字母(网页源代码中)

1 import re
2 with open(‘data‘,‘r‘) as f:
3     str = f.read().strip()
4     res=‘‘.join()re.findall(r‘[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]‘,str))  #findall方法返回每个字母组成的list,[^]为不包含的意思
5     if(res):
6         print(res)
7 --->linkedlist

4:先点击图片后发现是个多级跳转,第一个参数是33110

 1 from urllib import request
 2 import re
 3 value=33110
 4 while True:
 5     with request.urlopen(‘http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%d‘%value) as f:
 6         data = f.read().decode(‘utf-8‘)
 7         res = re.findall(r‘(\d+)‘,data)
 8         value = int(res[0])
 9         print(value)
10 最后得到66831,跳转后得到peak.html

5:这道题太扯了,peak hell连读成了pickle,pickle虽然知道但是从来没用过。
  参考:    
  将page source里点击banner.p出现的东西保存成文件banner.p放到同目录下
  序列化后出来是[[(‘ ‘, 95)], [(‘ ‘, 14), (‘#‘, 5), (‘ ‘, 70), (‘#‘, 5), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘,   4)]...]]根本就不知道是啥
  输出成如下格式后:

 1 [[(‘ ‘, 95)], [(‘ ‘, 14), (‘#‘, 5), (‘ ‘, 70), (‘#‘, 5), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)], [(‘ ‘, 6), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 9), (‘#‘, 3), (‘ ‘, 7), (‘#‘, 5), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 4),
 2 [(‘ ‘, 95)]
 3 [(‘ ‘, 14), (‘#‘, 5), (‘ ‘, 70), (‘#‘, 5), (‘ ‘, 1)]
 4 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
 5 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
 6 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
 7 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
 8 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
 9 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
10 [(‘ ‘, 15), (‘#‘, 4), (‘ ‘, 71), (‘#‘, 4), (‘ ‘, 1)]
11 [(‘ ‘, 6), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 9), (‘#‘, 3), (‘ ‘, 7), (‘#‘, 5), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 5), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 10), (‘#‘, 3), (‘ ‘, 7), (‘#‘, 4), (‘ ‘, 1)]
12 [(‘ ‘, 3), (‘#‘, 3), (‘ ‘, 3), (‘#‘, 2), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 7), (‘ ‘, 5), (‘#‘, 2), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 7), (‘ ‘, 3), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 7), (‘ ‘, 5), (‘#‘, 3), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1)]
13 [(‘ ‘, 2), (‘#‘, 3), (‘ ‘, 5), (‘#‘, 3), (‘ ‘, 2), (‘#‘, 5), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 3), (‘#‘, 4), (‘ ‘, 4), (‘#‘, 5), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 5), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 5), (‘#‘, 3), (‘ ‘, 3), (‘#‘, 4), (‘ ‘, 1)]
14 [(‘ ‘, 1), (‘#‘, 3), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 1)]
15 [(‘ ‘, 1), (‘#‘, 3), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 10), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 7), (‘#‘, 3), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 1)]
16 [(‘#‘, 4), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 2), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 4), (‘ ‘, 7), (‘#‘, 3), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 1)]
17 [(‘#‘, 4), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 10), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 14), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 1)]
18 [(‘#‘, 4), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 4), (‘ ‘, 12), (‘#‘, 4), (‘ ‘, 1)]
19 [(‘#‘, 4), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 4), (‘ ‘, 12), (‘#‘, 4), (‘ ‘, 1)]
20 [(‘ ‘, 1), (‘#‘, 3), (‘ ‘, 11), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 12), (‘#‘, 4), (‘ ‘, 1)]
21 [(‘ ‘, 2), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 2), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 2), (‘ ‘, 3), (‘#‘, 4), (‘ ‘, 1)]
22 [(‘ ‘, 3), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 2), (‘ ‘, 3), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 3), (‘#‘, 11), (‘ ‘, 3), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 2), (‘#‘, 4), (‘ ‘, 5), (‘#‘, 4), (‘ ‘, 4), (‘#‘, 3), (‘ ‘, 4), (‘#‘, 2), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 1)]
23 [(‘ ‘, 6), (‘#‘, 3), (‘ ‘, 5), (‘#‘, 6), (‘ ‘, 4), (‘#‘, 5), (‘ ‘, 4), (‘#‘, 2), (‘ ‘, 4), (‘#‘, 4), (‘ ‘, 1), (‘#‘, 6), (‘ ‘, 4), (‘#‘, 11), (‘ ‘, 4), (‘#‘, 5), (‘ ‘, 6), (‘#‘, 3), (‘ ‘, 6), (‘#‘, 6)]
24 [(‘ ‘, 95)]

  考虑可能是空格画图,然后用了开头大神的代码

1 import pickle
2 with open(‘banner.p‘,‘r‘) as f:
3     object = pickle.load(f)
4     print object
5     for item in object:
6         print ‘‘.join(map(lambda p: p[0]*p[1], item))       #此步最重要,我弄了半天没能看出来结果是channel
 1 *此中有个值得思考的问题是若是用平时的读写文件,如一个文件保存了如下数据
 2     [(‘ ‘,2),(‘#‘,1),(‘ ‘,1)]
 3     [(‘ ‘,1),(‘#‘,3),(‘ ‘,1)]
 4     [(‘#‘,5)]
 5     应当还是用此地的原理每行读出后拼成字符串后打印。但有个问题是f.readlines()读出的是str型。那么如何转换成list呢?
 6     import re
 7     with open(‘banner.test‘,‘r‘) as f:
 8         for line in f.readlines():
 9             result = re.findall(r"‘(.)‘.(.)",line)   #用正则提取出来的元素刚好是成为list的元素,所以就完美的解决了这个问题
10             print type(result)
11             print ‘‘.join(map(lambda x: x[0]*int(x[1]), result))
时间: 2024-08-24 19:31:29

python challenge 待续中的相关文章

Python Challenge 6

第6关: 既然下面的与riddle没有关系,那就不要管了啦,想哥什么时候有钱了再汇给你呗.现在还只是工科屌丝一枚. 看上面,除了一个注释<!--zip-->就没了,拉进url一试,yes, find the zip. 压缩文件,再拉一个channel.zip就弄出来了. 剩下的与第5关类似. the next nothing is ... import urllib import urllib.request import zipfile import os import os.path im

Python&MySQL操作过程中遇到的编码问题

对于Python字符编码的理解 之前整理了一部分,这次主要是设计到数据库操作的. 下面是一些编码方面的概念和原理,以条目方式整理: CREATE DATABASE IF NOT EXISTS db_name DEFAULT CHARSET utf8 COLLATE utf8_general_ci; DEFAULT CHARSET是设置默认字符编码集,也就是数据在库内从存储编码,我的理解是在存储这个层面上的,如果SQL命令是以gbk方式传输数据的(cur.execute('SET NAMES ut

一个古老的编程游戏:Python Challenge全通攻略(转)

Python Challenge是一个网页闯关游戏,通过一些提示找出下一关的网页地址.与众不同的是,它是专门为程序员设计的,因为大多数关卡都要编程来算哦!! 去年和同学一起玩的,他做了大半,我做了小半,作弊了一些,33关全通,今天逛硬盘发现这个资料,拿出来晃晃. 非常非常非常非常好玩,强烈推荐编程的朋友都玩玩,不一定要会Python,我和我同学都不会,不过我们用C#一样能搞出来,没有障碍的. 0 http://www.pythonchallenge.com/pc/def/0.html 猜238,

Python Challenge 过关心得(0)

最近开始用Openerp进行开发,在python语言本身上并没有什么太大的进展,于是决定利用空闲时间做一点python练习. 最终找到了这款叫做Python Challenge(http://www.pythonchallenge.com)的编程游戏. 这款游戏年代十分久远了,不过据说题目难度到后面挺大,我很怀疑会在某些关卡卡上很长一段时间,反正就尝试着做做看吧,能做多少做多少,现在水平低就做前面的简单的,等水平上去了再慢慢挑战后面的关卡. 最开始的其实是第0关,图片上是一个数字238,下方提示

Python统计列表中的重复项出现的次数的方法

前言 在实际工作和学习中,经常会遇到很多重复的数据,但是我们又必须进行统计,所及这里简单介绍一下统计列表中重复项的出现次数的简单方法. 实例 本文实例展示了Python统计列表中的重复项出现的次数的方法,是一个很实用的功能,适合Python初学者学习借鉴.具体方法如下: #方法1: mylist = [1,2,2,2,2,3,3,3,4,4,4,4] myset = set(mylist)  #myset是另外一个列表,里面的内容是mylist里面的无重复 项 for item in myset

[Docker]在Python和IPython中使用Docker

现在Docker是地球上最炙手可热的项目之一,就意味着人民实际上不仅仅是因为这个才喜欢它. 话虽如此,我非常喜欢使用容器,服务发现以及所有被创造出的新趣的点子和领域来切换工作作为范例. 这个文章中我会简要介绍使用python中的docker-py模块来操作Docker 容器,这里会使用我喜爱的编程工具IPython. 安装docker-py 首先需要docker-py.注意这里的案例中我将会使用Ubuntu Trusty 14.04版本. $ pip install docker-py IPyh

Python 可视化Twitter中指定话题中Tweet的词汇频率

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-8 @author: guaguastd @name: plot_frequencies_words.py ''' if __name__ == '__main__': #import json # import Counter from collections import Counter # import search from search impor

Python 查找Twitter中最流行(转载最多)的10个Tweet

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: find_popular_retweets.py ''' # Finding the most popular retweets def popular_retweets(statuses): retweets = [ # Store out a tuple of these three values.

Python进阶-继承中的MRO与super

摘要本文讲述Python继承关系中如何通过super()调用"父类"方法,super(Type, CurrentClass)返回CurrentClass的MRO中Type的下一个类的代理:以及如何设计Python类以便正确初始化. 1. 单继承中父类方法调用 在继承中,调用父类方法是很有必要的.调用父类方法的场景有很多: 比如必须调用父类的构造方法__init__才能正确初始化父类实例属性,使得子类实例对象能够继承到父类实例对象的实例属性: 再如需要重写父类方法时,有时候没有必要完全摒