반응형
python challenge 6
welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip4와 어느정도 비슷하게 진행되는 문제인 것 같다. 그리하야 끝까지 가보았으나, 다음과 같은 문자열만 있었다.
Next nothing is 45100
Next nothing is 68628
Next nothing is 67824
Next nothing is 46145
Collect the comments.또 해매다가 어찌어찌 zip 파일에도 comment 란이 있었다는 걸 상기해낸 후, zipfile 모듈을 통해 쉽게 읽어들일 수도 있다는 걸 알아냈다.
#!/usr/bin/python3
import urllib.request, re, zipfile, io
data = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/channel.zip').read()
zfile = io.BytesIO()
zfile.write(data)
z = zipfile.ZipFile(zfile, 'r')
r = re.compile(r'Next nothing is (\d+)')
nothing = '90052'
result = ''
while True:
data = z.read(nothing + '.txt').decode('utf-8')
print(data)
result += z.getinfo(nothing + '.txt').comment.decode('utf-8')
if r.match(data):
nothing = data.split(' ')[-1]
else:
break
print(result)그리하야 www.pythonchallenge.com/pc/def/hokey.html에 가보면 다음과 같은 문자열을 얻을 수 있다.
it's in the air. look at the letters. 공기에 있는 거라고 하는데, hockey를 자세히 보면 'oxygen'이란 단어를 얻을 수 있다.
next : http://www.pythonchallenge.com/pc/def/oxygen.html solution : http://www.pythonchallenge.com/pcc/def/oxygen.html
반응형
'Write-up' 카테고리의 다른 글
| [Python Challenge] level 8 (0) | 2019.04.13 |
|---|---|
| [Python Challenge] level 7 (0) | 2019.04.13 |
| [Python Challenge] level 5 (0) | 2019.04.13 |
| [Python Challenge] level 4 (0) | 2019.04.13 |
| [Python Challenge] level 3 (0) | 2019.04.13 |