Skip to content

Commit 65621ae

Browse files
solved 28
1 parent 2c55790 commit 65621ae

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Diff for: 28.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import download_file
2+
3+
from PIL import Image
4+
5+
6+
def main():
7+
url = "http://www.pythonchallenge.com/pc/ring/bell.png"
8+
file_path = "ring/bell.png"
9+
username = "repeat"
10+
password = "switch"
11+
# first_step(url, file_path, username, password)
12+
second_step(file_path)
13+
14+
15+
def first_step(url, file_path, username, password):
16+
download_file.download_with_auth(url, file_path, username, password)
17+
18+
19+
def second_step(file_path):
20+
im = Image.open(file_path)
21+
green_channel = 1
22+
green_data = im.getdata(green_channel)
23+
datas = list(green_data)
24+
datas_len = len(datas)
25+
assert datas_len % 2 == 0
26+
message = ""
27+
for i in range(int(datas_len / 2)):
28+
index = 2 * i
29+
left = datas[index]
30+
right = datas[index + 1]
31+
abs_left_min_right = abs(left - right)
32+
if abs_left_min_right != 42:
33+
message += chr(abs_left_min_right)
34+
print(message)
35+
36+
37+
if __name__ == "__main__":
38+
main()

Diff for: README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# pythonchallenge
22
Solve Problems in http://www.pythonchallenge.com
33

4+
#### 28
5+
result: http://www.pythonchallenge.com/pc/ring/guido.html
6+
- use image.split() to split RGB channels
7+
- im.bands() return number of im's channels
8+
- ring means "green" if you visit "green.html" will get response "yes"
9+
- whodunnit is an word means "who is the murderer"
10+
11+
412
#### 27
513
result: http://www.pythonchallenge.com/pc/ring/bell.html auth=(repeat, switch)
614
- author use python2 keyword, but there is some different with python3

Diff for: ring/bell.png

654 KB
Loading

0 commit comments

Comments
 (0)