This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = <<'EOF' | |
# copy from the source page | |
EOF | |
puts s.scan(/[a-z]/).join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 我的代码,判断每个字符是否是字母 | |
import re | |
astring = '''copy from the source page''' | |
bstring = '' | |
for a in astring: | |
if re.match('[a-zA-Z]',a): | |
bstring = bstring+a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gets.tr "a-z", "c-zab" | |
# 就这么简单!然后输入字符串就好了!真让人喜欢! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xmlrpclib | |
xmlrpclib.ServerProxy('http://www.pythonchallenge.com/pc/phonebook.php').phone('Bert') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 一定要注意,读写文件要强调是二进制 | |
evil = File.open("evil2.gfx", 'rb').read | |
outputs = (0..4).map { |i| File.open("out#{i}", "wb") } | |
evil.each_char.with_index { |c, i| outputs[i%5].write(c) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raw = open('evil2.gfx','rb').read() | |
for i in range(5): | |
open('out%d'%i, 'wb').write(raw[i::5]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "RMagick" | |
img = Magick::ImageList.new 'cave.jpg' | |
r, c = img.rows, img.columns | |
for i in 0..r-2 | |
for j in 0..c-1 | |
if (i+j).odd? | |
p = img.get_pixels(j, i+1, 1, 1) | |
img.store_pixels(j, i, 1, 1, p) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
img = Image.open("cave.jpg") | |
c,r = img.size | |
pix = img.load() | |
for j in range(r-1): | |
for i in range(c): | |
if (i+j)%2: | |
pix[i,j] = pix[i,j+1] | |
img.show() | |
# 注意也可以用 img.getpixel 和 img.putpixel 来操作像素。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f n | |
n == 0 ? "1": | |
f(n-1).scan(/(\d)(\1*)/).collect{|i| "#{i[1].size+1}#{i[0]}"}.join | |
end | |
puts f(30).size |