Skip to content

Instantly share code, notes, and snippets.

@lufeihaidao
lufeihaidao / python_challenge_q8.rb
Created April 13, 2014 15:42
Q8 of python challenge
require 'bzip2'
un = "同上,需要用双引号括起来"
pw = "同上,需要用双引号括起来"
puts Bzip2.uncompress(un), Bzip2.uncompress(pw)
@lufeihaidao
lufeihaidao / python_challenge_q8.py
Created April 13, 2014 15:42
Q8 of python challenge
import bz2
un = "un 的字符串内容,表示 user name"
pw = "pw 的字符串内容,表示 password"
print bz2.decompress(un), bz2.decompress(pw)
@lufeihaidao
lufeihaidao / python_challenge_q7.rb
Created April 13, 2014 15:40
Q7 of python challenge
require "RMagick"
Magick::ImageList.new("oxygen.png").get_pixels(0,45,629,1).map.with_index
{|p,i| (p.red/255).chr if i%7==0)}.join.scan(/\d+/){|c| print c.to_i.chr }
@lufeihaidao
lufeihaidao / python_challenge_q7.py
Created April 13, 2014 15:39
Q7 of python challenge
import re, Image
im = Image.open("oxygen.png")
row = [im.getpixel((x, 47)) for x in range(0, im.size[0], 7)]
chrs = [chr(r) for r, g, b, a in row if r == g == b]
s = ''.join(chrs)
print ''.join(map(chr, map(int, re.findall(r'\d+',s))))
@lufeihaidao
lufeihaidao / python_challenge_q6.rb
Created April 13, 2014 15:28
Q6 of python challenge
require "zip/zip"
zipfilename = "/home/haidao/Downloads/channel.zip"
Zip::ZipFile.open(zipfilename) do |zipfile|
s = zipfile.get_input_stream("readme.txt").read
num = s.match(/\d{2,6}/)
output = Array.new
while num do
entry = zipfile.find_entry("#{num}.txt")
s = entry.get_input_stream.read
num = s.match(/\d{2,6}/)
@lufeihaidao
lufeihaidao / python_challenge_q6.py
Created April 13, 2014 15:27
Q6 of python challenge
f = "channel.zip"
z = zipfile.ZipFile(f)
name = '90052.txt'
while 1:
print z.getinfo(name).comment,
name = z.read(name).split()[-1] + '.txt'
@lufeihaidao
lufeihaidao / python_challenge_q5.py
Created April 13, 2014 15:25
Q5 of python challenge
# 推荐的做法
import urllib2, sys, pickle
pickle_data = urllib2.urlopen('http://www.pythonchallenge.com/pc/def/banner.p').read()
data = pickle.loads(pickle_data)
for line in data:
for char, count in line: sys.stdout.write(char * count)
sys.stdout.write("\n")
@lufeihaidao
lufeihaidao / python_challenge_q4.sh
Created April 13, 2014 15:19
Q4 of python challenge
ruby -wle 'n = 12345; print n = $1 while
`GET "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=#{n}"`
=~ /(\d+)$/'
@lufeihaidao
lufeihaidao / python_challenge_q4.rb
Created April 13, 2014 15:16
Q4 of python challenge
require "open-uri"
n=12345
loop do
flag = ''
open("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=#{n}") do |f|
s=f.read
flag = s if s=~/htm/
n=(s=~/div/ ? n/2 : s.split[-1].to_i)
end
if !flag.empty?
@lufeihaidao
lufeihaidao / python_challenge_q4.py
Created April 13, 2014 15:15
Q4 of python challenge
import re
from urllib import urlopen
astring='http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
temp='12345'
f = urlopen(astring+temp)
a=f.read()
restring=re.compile('and the next nothing is (\d{3,5})')
for i in range(400):
temp=re.findall(restring,a)[0]
print(temp)