Skip to content

Commit e745e30

Browse files
committed
add solution for level 9
1 parent 8ea06bf commit e745e30

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

PythonChallenge/PythonChallenge.pyproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<SchemaVersion>2.0</SchemaVersion>
66
<ProjectGuid>c9109357-7323-45c6-89bb-815d766f04c8</ProjectGuid>
77
<ProjectHome>.</ProjectHome>
8-
<StartupFile>level_8.py</StartupFile>
8+
<StartupFile>level_9.py</StartupFile>
99
<SearchPath>
1010
</SearchPath>
1111
<WorkingDirectory>.</WorkingDirectory>
@@ -49,6 +49,9 @@
4949
<Compile Include="level_8.py">
5050
<SubType>Code</SubType>
5151
</Compile>
52+
<Compile Include="level_9.py">
53+
<SubType>Code</SubType>
54+
</Compile>
5255
<Compile Include="utils.py">
5356
<SubType>Code</SubType>
5457
</Compile>

PythonChallenge/level_9.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import re
2+
import utils
3+
from PIL import Image, ImageDraw
4+
5+
6+
def level_9(text):
7+
"""Find the coordinates in the comments and draw the lines."""
8+
mo = re.search(r'first:((\d*,?)*)', text.replace('\n', ''))
9+
if mo:
10+
first_pat = mo.group(1)
11+
first = [int(num) for num in first_pat.split(',')]
12+
im = Image.new('RGBA', (max(first) + 10, max(first) + 10))
13+
draw = ImageDraw.Draw(im)
14+
draw.line(first)
15+
16+
mo = re.search(r'second:((\d*,?)*)', text.replace('\n', ''))
17+
if mo:
18+
second_pat = mo.group(1)
19+
second = [int(num) for num in second_pat.split(',')]
20+
draw.line(second)
21+
im.show()
22+
23+
24+
if __name__ == '__main__':
25+
comments = utils.get_comments(
26+
'http://www.pythonchallenge.com/pc/return/good.html', user='huge')
27+
if comments:
28+
for comment in comments:
29+
level_9(comment)
30+
else:
31+
print(" [*] No comments found.")

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ Level | Complete? | Name
7474
6 | Y | http://www.pythonchallenge.com/pc/def/channel.html
7575
7 | Y | http://www.pythonchallenge.com/pc/def/oxygen.html
7676
8 | Y | http://www.pythonchallenge.com/pc/def/integrity.html
77-
9 | N | http://www.pythonchallenge.com/pc/return/good.html
78-
10 | N |
77+
9 | Y | http://www.pythonchallenge.com/pc/return/good.html
78+
10 | N | http://www.pythonchallenge.com/pc/return/bull.html
7979
11 | N |
8080
12 | N |
8181
13 | N |

0 commit comments

Comments
 (0)