python challenge

# 0
print 2 ** 238
# 274877906944
# http://www.pythonchallenge.com/pc/def/274877906944.html
# 1
key = "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."

def func(src):
    src = src.lower()
    return "".join([chr(ord('a') + ((ord(i) - ord('a') + 2) % 26)) if ord(i) >= ord('a') and ord(i) <= ord('z') else i for i in src])

print func(key)
# 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. using string.maketrans() is recommended. now apply on the url.

print func('map')
# ocr
# http://www.pythonchallenge.com/pc/def/ocr.html
# 2
import urllib
import re

page = urllib.urlopen("http://www.pythonchallenge.com/pc/def/ocr.html")
html = page.read()
page.close()

pattern = re.compile(r'<!--(.+?)-->', re.S)
res = pattern.findall(html)[1]

res = res.replace('\n', '')
print res

print "".join(re.findall(r'[a-zA-Z]+', res))
# equality
# http://www.pythonchallenge.com/pc/def/equality.html

 

# 3 
# a small letter surrounded EXACTLY three big letter on each of its sides
import urllib
import re

page = urllib.urlopen("http://www.pythonchallenge.com/pc/def/equality.html")
html = page.read()
page.close()

res = re.findall(r'<!--(.+?)-->', html, re.S)[0]

key = re.findall(r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', res, re.S)

print len(key)
print key
# ['l', 'i', 'n', 'k', 'e', 'd', 'l', 'i', 's', 't']
# http://www.pythonchallenge.com/pc/def/linkedlist.html
# 4
import urllib2
import re

pattern = re.compile('\d+')
index = "12345"
url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="

for i in range(0, 400):
    page = urllib2.urlopen(url + index)
    html = page.read()
    res = pattern.findall(html)
    if res:
        print res[-1]
        index = res[-1]
    else:
        if html.find('Divide by two and keep going.') != -1:
            index = str(int(index) / 2)
        else:
            print i, html
            break
    page.close()

# 16044
# Yes. Divide by two and keep going.

# 250 peak.html
# http://www.pythonchallenge.com/pc/def/peak.html
# 5
import pickle
import urllib2

page = urllib2.urlopen("http://www.pythonchallenge.com/pc/def/banner.p")
html = page.read()

reader = pickle.loads(html)

print reader

for i in reader:
    print "".join(c[0] * c[1] for c in i)

# http://www.pythonchallenge.com/pc/def/channel.html
# 6
import zipfile
import urllib
import re
import os
import shutil

urllib.urlretrieve("http://www.pythonchallenge.com/pc/def/channel.zip", "channel.zip")
unzipfile = zipfile.ZipFile("channel.zip", 'r')
unzipfile.extractall('channel')

# read the zip readme.txt

pattern = re.compile('\d+')
index = '90052'
key = ""
for i in range(0, 900):
    f = open("channel/" + index + '.txt', 'r')
    # print comment, 901 files
    key = key + unzipfile.getinfo(index + '.txt').comment
    source = f.readline()
    next = pattern.findall(source)
    f.close()
    if next:
        index = next[-1]
    else:
        if source.find("Divide by two and keep going.") != -1:
            index = str(int(index) / 2)
        else:
            print index, source
            break

unzipfile.close()

print key

shutil.rmtree(os.path.join(os.getcwd(), 'channel'))
os.remove(os.path.join(os.getcwd(), 'channel.zip'))

# 46145 Collect the comments.

# get HOCKEY

# direct to http://www.pythonchallenge.com/pc/def/hockey.html
# it's in the air. look at the letters. look the letters, they are fixed with 'oxygen', so
# http://www.pythonchallenge.com/pc/def/oxygen.html
# 7
from PIL import Image
import urllib
import os
import re

urllib.urlretrieve("http://www.pythonchallenge.com/pc/def/oxygen.png", "oxygen.png")

img = Image.open("oxygen.png", 'r')
w = img.size[0]

key = ""

for i in range(0, w-1, 7):
    pixel = img.getpixel((i, 47))
    print pixel
    key += chr(int(pixel[0]))

print key[:-3]
os.remove("oxygen.png")

pattern = re.compile('\d+')
res = pattern.findall(key[:-3])
print "".join([chr(int(i)) for i in res])

# smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
# integrity
# http://www.pythonchallenge.com/pc/def/integrity.html

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值