Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c55790

Browse files
solved 27
1 parent1e0a2e3 commit2c55790

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

‎27.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
importdownload_file
22

33
fromPILimportImage
4+
importbz2
5+
importpy2keywords
46

57

68
defmain():
@@ -10,9 +12,12 @@ def main():
1012
user="butter"
1113
password="fly"
1214
# first_step(url, file_path, user, password)
13-
raw,result=second_step(file_path)
15+
im,raw,result=second_step(file_path)
1416
raw_ary,result_ary=third_step(raw,result)
15-
fourth_step(raw_ary,result_ary)
17+
raw_str,result,index=fourth_step(raw_ary,result_ary)
18+
hint_path="zigzag/{}".format("hint.png")
19+
five_step(im,index,hint_path)
20+
six_step(raw_str)
1621

1722

1823
deffirst_step(url,file_path,user,password):
@@ -27,7 +32,7 @@ def second_step(file_path):
2732
value="".join([chr(palette[i])foriinrange(len(palette))])
2833
table=str.maketrans(index,value)
2934
result=raw.decode("latin1").translate(table).encode("latin1")
30-
returnraw,result
35+
returnim,raw,result
3136

3237

3338
defthird_step(raw,result):
@@ -42,7 +47,44 @@ def third_step(raw, result):
4247

4348

4449
deffourth_step(raw_ary,result_ary):
45-
pass
50+
zero=raw_ary.pop(0)
51+
raw_ary.append(zero)
52+
assertlen(raw_ary)==len(result_ary)
53+
raw= []
54+
result= []
55+
index= []
56+
foriinrange(len(raw_ary)):
57+
raw_i=raw_ary[i]
58+
result_i=result_ary[i]
59+
ifraw_i!=result_i:
60+
raw.append(raw_i)
61+
result.append(result_i)
62+
index.append(i)
63+
raw_str=b""
64+
foriinrange(len(raw)):
65+
raw_str+=chr(raw[i]).encode("latin1")
66+
returnraw_str,result,index
67+
68+
69+
deffive_step(im,index,hint_path):
70+
im2=Image.new("RGB",im.size)
71+
colors= [(255,255,255)]* (im2.size[0]*im2.size[1])
72+
foriinindex:
73+
colors[i]= (0,0,255)
74+
im2.putdata(colors)
75+
im2.save(hint_path)
76+
print("Hint in {}".format(hint_path))
77+
78+
79+
defsix_step(raw_str):
80+
raw_dec=bz2.decompress(raw_str)
81+
strs=raw_dec.decode("latin1").split(" ")
82+
results=set()
83+
foriinrange(len(strs)):
84+
s=strs[i]
85+
ifnotsinpy2keywords.kwlist:
86+
results.add(s)
87+
print(results)
4688

4789

4890
if__name__=="__main__":

‎README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#pythonchallenge
22
Solve Problems inhttp://www.pythonchallenge.com
33

4+
####27
5+
result:http://www.pythonchallenge.com/pc/ring/bell.html auth=(repeat, switch)
6+
- author use python2 keyword, but there is some different with python3
7+
- use assert to do assert
8+
- tobytes() method for Image in PIL: Return image as a bytes object.
9+
- getpalette() method for Image in PIL: Returns the image palette as a list.
10+
11+
412
####26
513
result:http://www.pythonchallenge.com/pc/hex/speedboat.html
614
```python

‎py2keywords.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kwlist= ['and','as','assert','break','class','continue','def','del','elif','else','except','exec','finally','for','from','global','if','import','in','is','lambda','not','or','pass','print','raise','return','try','while','with','yield']

‎zigzag/hint.png

4.57 KB
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp