Skip to content

Commit 6aa4c22

Browse files
committed
5-8
1 parent aad751c commit 6aa4c22

File tree

5 files changed

+130
-1
lines changed

5 files changed

+130
-1
lines changed

p4.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,17 @@
1010
http://www.pythonchallenge.com/pc/def/linkedlist.php
1111
'''
1212

13+
import urllib
14+
import re
15+
1316
if __name__ == "__main__":
14-
17+
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
18+
#num = "12345"
19+
# 92118 Yes. Divide by two and keep going.
20+
num = "46059"
21+
# 65667 peak.html
22+
23+
while 1:
24+
data = urllib.urlopen(url + num).read()
25+
num = "".join(re.findall("and the next nothing is ([0-9]+)", data))
26+
print num

p5.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
5+
Author:
6+
7+
http://www.kylewu.net
8+
9+
File: p5.py
10+
Create Date: Fri Nov 26 10:11:24 2010
11+
12+
http://www.pythonchallenge.com/pc/def/peak.html
13+
'''
14+
15+
import urllib
16+
import pickle
17+
18+
if __name__ == "__main__":
19+
20+
p = handle = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p")
21+
data = pickle.load(p)
22+
print type(data)
23+
for elm in data:
24+
print "".join([e[0] * e[1] for e in elm])
25+
#print elm
26+

p6.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'''
2+
3+
Author:
4+
5+
http://www.kylewu.net
6+
7+
File: p6.py
8+
Create Date: Fri Nov 26 10:39:57 2010
9+
10+
http://www.pythonchallenge.com/pc/def/channel.html
11+
'''
12+
13+
import zipfile
14+
import re
15+
import urllib
16+
import os
17+
18+
if __name__ == "__main__":
19+
source = 'http://www.pythonchallenge.com/pc/def/channel.zip'
20+
save_as = 'temp.zip'
21+
urllib.urlretrieve(source, save_as)
22+
23+
zf = zipfile.ZipFile(save_as, 'r')
24+
f = '90052'
25+
res = []
26+
27+
print zf.read('46145.txt')
28+
29+
while 1:
30+
try:
31+
data = zf.read('%s.txt' % f)
32+
f = "".join( re.findall("is ([0-9]+)", data) )
33+
res.append(zf.getinfo('%s.txt' % f).comment)
34+
print f
35+
except:
36+
print "".join(res)
37+
break
38+
39+
os.remove(save_as)

p7.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
3+
Author:
4+
5+
http://www.kylewu.net
6+
7+
File: p7.py
8+
Create Date: Fri Nov 26 11:10:24 2010
9+
10+
http://www.pythonchallenge.com/pc/def/oxygen.html
11+
12+
'''
13+
14+
#TODO don't know why
15+
import urllib
16+
import os
17+
import Image
18+
import re
19+
20+
if __name__ == "__main__":
21+
source = 'http://www.pythonchallenge.com/pc/def/oxygen.png'
22+
save_as = 'temp.png'
23+
urllib.urlretrieve(source, save_as)
24+
25+
i = Image.open(save_as)
26+
row = [i.getpixel((x, 45)) for x in range(0, i.size[0], 7)]
27+
ords = [r for r, g, b, a in row if r == g == b]
28+
print "".join(map(chr, map(int, re.findall("\d+", "".join(map(chr, ords))))))
29+
30+
31+
#box = ()
32+
#region = image.crop(box)
33+
os.remove(save_as)

p8.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
3+
4+
'''
5+
6+
Author:
7+
8+
http://www.kylewu.net
9+
10+
File: p8.py
11+
Create Date: Fri Nov 26 13:10:23 2010
12+
13+
'''
14+
import bz2
15+
if __name__ == "__main__":
16+
un = "BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084";
17+
pw = "BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08";
18+
print bz2.decompress(un)
19+
print bz2.decompress(pw)

0 commit comments

Comments
 (0)