War game/pythonchallenge

pythonchallenge level7

badcob 2009. 10. 16. 02:12

http://www.pythonchallenge.com/pc/def/hockey.html

문제의 링크에는  it's in the air. look at the letters. 라고 적혀있다.
공기중에 있는것. oxygen를 url로 입력해보았다.

http://www.pythonchallenge.com/pc/def/oxygen.html

가운데 회색 바가 수상해 보이는 그림 파일 하나가 나온다. Python Imaging Library (PIL)를 사용해
회색 바 부분만을 뽑아내 보자. getpixel method를 사용하면 픽셀별로 RGB값을 튜플로 얻어낼 수 있다.

The Other RGB Color Chart (http://www.tayloredmktg.com/rgb/)에 보면 Gray의 RGB 코드는
190-190-190 이다. 먼저 그림의 세로 픽셀을 조사해서 190-190-190이 나오는 부분을 찾은 뒤에
가로 픽셀을 조사해서 RGB 코드가 다른 값이 나오는 부분까지 구한다. 그렇게 구한 회색바 픽셀들의
RGB 값을 chr 함수로 캐릭터로 바꾸면 읽을 수 있는 문자열들이 보인다.

사용한 코드는 아래와 같다.

import Image
im = Image.open("oxygen.png")
print im.size
x = im.size[0]
y = im.size[1]
print x,y

i=0
j=0
while i < y:
      pix1 = im.getpixel((0,i))
      if pix1[0] == pix1[1] == pix1[2]:
          break
      i += 1

while j < x:
    pix2 = im.getpixel((j,i))
    if not pix2[0] == pix2[1] == pix2[2]:
        break
    j += 1
    
print j,i

temp = ''
result = ''

for a in range(0,j,7):
  pixel = im.getpixel((a,i))
  temp = chr(pixel[1])
  result +=temp
print result



위의 코드를 실행하면 반복된 문자열들이 나타난다.

sssssmmmmmmmaaaaaaarrrrrrrttttttt       ggggggguuuuuuuyyyyyyy,,,,,,,      
yyyyyyyooooooouuuuuuu       mmmmmmmaaaaaaadddddddeeeeeee       iiiiiiittttttt.......      
ttttttthhhhhhheeeeeee       nnnnnnneeeeeeexxxxxxxttttttt       llllllleeeeeeevvvvvvveeeeeeelllllll   
   
이것은 for문에서 range(0,j,7) 이렇게 바꿔서 깔끔하게 볼 수 있었다.

smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

숫자들을 캐릭터로 바꿔보면 integrity 임을 알 수 있다.

http://www.pythonchallenge.com/pc/def/integrity.html