'2011/06/22'에 해당되는 글 3건
- 2011.06.22 [Python challenge Level7] - oxygen (PIL로 pixel값 처리)
- 2011.06.22 [Python challenge Level6] - channel (zipfile)
- 2011.06.22 [Python challenge Level5] - peak (pickle) 1
[ Problem ] - http://www.pythonchallenge.com/pc/def/oxygen.html
♧ 가운데 회색 바가 수상해 보인다. 해당 격자를 7픽셀 단위로 RGB값을 뽑아서 ASCII문자로 변환 해야 하는데 파이썬에는 내장된 이미지 라이브러리가 없음으로 Python Imaging Library (PIL)를 사전에 설치 하자.
♧ 처리 순서는 아래와 같다.
import Image, urllib, StringIO, re # coding=utf8 # ① 이미지 파일 오픈. u_img = urllib.urlopen("http://www.pythonchallenge.com/pc/def/oxygen.png").read() img = Image.open(StringIO.StringIO(u_img)) # ② 이미지 길이와 회색바 위치 구함. middle = (img.size[1]/2) width = img.size[0] # ③ 7픽셀 단위로 RGB값 구함 pixels = [img.getpixel((x, middle)) for x in range(0, width, 7)] # ④ pixels값의 R,G,B가 동일한 값만을 뽑아낸다. ords = [r for r,g,b,a in pixels if r == g == b] # ⑤ 뽑아낸 RGB값은 ASCII값으로 문자로 변환 출력. result = ''.join(map(chr, ords)) print result # ⑥ 출력된 결과의 또다른 ASCII값을 찾아 int형 변환->chr변환->출력. print ''.join(map(chr, map(int, re.findall("\d+", result)))) [ 출력 결과 ]
(※ 사용한 PIL의 모듈은 레퍼런스 문서를 참조) |
[ Solution ] - http://www.pythonchallenge.com/pcc/def/integrity.html
(※ 문제에 대한 다양한 해결법은 링크 참조.)
'워게임(WarGame) > PythonChallenge' 카테고리의 다른 글
[Python challenge Level9] - good (ImageDraw) (0) | 2011.06.23 |
---|---|
[Python challenge Level8] - integrity (bz2) (0) | 2011.06.23 |
[Python challenge Level6] - channel (zipfile) (0) | 2011.06.22 |
[Python challenge Level5] - peak (pickle) (1) | 2011.06.22 |
[Python challenge Level4] – linkedlist (urllib) (0) | 2011.06.21 |
[ problem ] - http://www.pythonchallenge.com/pc/def/channel.html
♧ 청바지에 zipper 사진만 덩그러니 있다. 일단 소스를 보자.
맨 위에 "zip" 주석이 보인다.
♧ ("http://www.pythonchallenge.com/pc/def/channel.zip") 다운을 받고 "README.txt"를
궁금함을 뒤로 하고 'nothing'을 을 쫒아 가다 보면 "Collect the comments." 라는 문구가 보인다.
♧ 힌트를 종합해 보면 zip 안에 주석문을 모아야 한다. (※ zipfile 모듈을 이용)
♧ 다시 zipfile 모듈을 이용하여 주석을 모으면 "HOCKEY"라는 단어가 보인다.
URL을 고쳐 다시 쿼리를 보내면 "it's in the air. look at the letters." 문구가 보인다. 주석을 모은 메시지 출력문을 자세히 보면 "OXYGEY"라는 단어가 보인다. |
[ Solution ] - http://www.pythonchallenge.com/pcc/def/oxygen.html
(※ 문제에 대한 다양한 해결법은 링크 참조.)
'워게임(WarGame) > PythonChallenge' 카테고리의 다른 글
[Python challenge Level8] - integrity (bz2) (0) | 2011.06.23 |
---|---|
[Python challenge Level7] - oxygen (PIL로 pixel값 처리) (0) | 2011.06.22 |
[Python challenge Level5] - peak (pickle) (1) | 2011.06.22 |
[Python challenge Level4] – linkedlist (urllib) (0) | 2011.06.21 |
[Python challenge Level3] – equality (Regular Expression) (0) | 2011.06.21 |
[ Problem ] - http://www.pythonchallenge.com/pc/def/peak.html
♧ "pronounce it" 발음해라? 일단 소스를 보자!
알수 없는<peakhell> 태그에 "banner.p" 이 보인다. 일단 다운받자! (※ "peakhell" 발음을 몇 번 큰소리로 말하면 "pickle" 모듈의 발음 소리와 비슷하다.) ♧ "banner.p"를 노트패드로 열어 보면 알 수 없는 문자들이 보인다. (피클링된 객체)
이 알 수 없는 문자들을 pickle 모듈을 이용해서 unpickle 해야 한다. ( ※ 참조 : "파이썬 영속성 관리", "http://docs.python.org/library/pickle.html") ♧ unpickle하면 리스트와 튜플안에 문자와 숫자가 보이는데 이것을 문자*숫자로 풀어보면 "channel"이란 단어가 보인다.
|
[ Solution ] - http://www.pythonchallenge.com/pcc/def/channel.html
(※ 문제에 대한 다양한 해결법은 링크 참조.)
'워게임(WarGame) > PythonChallenge' 카테고리의 다른 글
[Python challenge Level7] - oxygen (PIL로 pixel값 처리) (0) | 2011.06.22 |
---|---|
[Python challenge Level6] - channel (zipfile) (0) | 2011.06.22 |
[Python challenge Level4] – linkedlist (urllib) (0) | 2011.06.21 |
[Python challenge Level3] – equality (Regular Expression) (0) | 2011.06.21 |
[Python challenge Level2] - ocr (특문 속에 알파벳) (0) | 2011.06.21 |