Skip to content

Instantly share code, notes, and snippets.

git clone git://github.com/imathis/octopress.git octopress
cd octopress # If you use RVM, You'll be asked if you trust the .rvmrc file (say yes).
ruby --version # Should report Ruby 1.9.3
@lufeihaidao
lufeihaidao / python_challenge_q1_1.py
Created April 9, 2014 16:01
Q1 of python challenge in python
# 这是我的 python 解法,相当的 C 呢
astring='''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.'''
import re
bstring=''
for a in astring:
if re.match('\w',a):
a=chr((ord(a)-95)%26+97)
bstring=bstring+a
@lufeihaidao
lufeihaidao / python_challenge_q1_2.py
Created April 9, 2014 16:14
Q1 of python challenge in python
# 推荐的做法
import string
text='''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.'''
table = string.maketrans(string.ascii_lowercase,
string.ascii_lowercase[2:]+string.ascii_lowercase[:2])
text.translate(table)
@lufeihaidao
lufeihaidao / python_challenge_q1.rb
Created April 13, 2014 14:58
Q1 of python challenge in ruby
gets.tr "a-z", "c-zab"
# 就这么简单!然后输入字符串就好了!真让人喜欢!
@lufeihaidao
lufeihaidao / python_challenge_q2.py
Created April 13, 2014 15:01
Q2 of python challenge in python
# 我的代码,判断每个字符是否是字母
import re
astring = '''copy from the source page'''
bstring = ''
for a in astring:
if re.match('[a-zA-Z]',a):
bstring = bstring+a
@lufeihaidao
lufeihaidao / python_challenge_q2.rb
Created April 13, 2014 15:03
Q2 of python challenge in ruby
s = <<'EOF'
# copy from the source page
EOF
puts s.scan(/[a-z]/).join
@lufeihaidao
lufeihaidao / python_challenge_q3.py
Last active August 29, 2015 13:59
Q3 of python challenge
# 我的代码比较笨,但是方法是一样的,就不贴上来了。
import re
s = '''
copy from the source page
'''
print ''.join(re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', s))
@lufeihaidao
lufeihaidao / python_challenge_q3.rb
Created April 13, 2014 15:11
Q3 of python challenge
s = <<'EOF'
copy from the source page
EOF
puts s.scan(/[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]/).join
@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)
@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?