Python/Python Challenge

[Python Challenge 23] 보너스 타임! 기본으로 돌아갈 때

Python Challenge 23의 Url은 다음과 같다

Python challenge 23 : http://www.pythonchallenge.com/pc/hex/bonus.html


구성

화면에는 누렁이가 있다. 특별한 건 안보이니까 주석을 보자

영어는 다음과 같이 써있다.

  • 해야 할 일 : 사과를 구해야 할 일이 있었나요? 지금이 바로 그 사람에게 사과를 할 좋은 시간이빈다. 이 레벨에서 할일이 딱히 없더라도 그사람에게 좋은 매너를 보여주세요
  • 찾을 수 없을 거예요. 이건 문서화 안된 모듈입니다.
  • 'va gur snpr bs jung?'

으흠; 해결 아이디어를 바로 만나보자


해결 아이디어

  • 'va gur snpr bs jung?'

이거의 해석이 먼저이다.

정말 출제자에게 미안한 이야기이지만, 보자마자 rot13이겠다 싶었다. 너무 영어 문장처럼 생겼다. Python code로 짜는 거 정도야 아주 예전에 풀었던 문제에서 할 수 있지만, 우리 조금 출제자의 의도대로 움직여 주자. 두 번째 주석인 문화 되지 않은 모듈이라는 점에서 힌트를 얻자. 문서화되지 않은 모듈 중 rot13과 밀접하게 동작을 하는 모듈은 의외로 Python principle이라고 여겨지는 'this'모듈이다.

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

뭐 그렇다. 특히 이 this라는 모듈은 this.s라는 클래스 문자열을 가지고 있는데, 

>>> print(this.s)
Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!

이렇다. 이 문자열은 rot13으로 암호화되어있으며, 해독을 위해서는 this.d딕셔너리에 매핑해야 된다.

>>> this.d
{'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', 'F': 'S', 'G': 'T', 'H': 'U', 
'I': 'V', 'J': 'W', 'K': 'X', 'L': 'Y', 'M': 'Z', 'N': 'A', 'O': 'B', 'P': 'C', 
'Q': 'D', 'R': 'E', 'S': 'F', 'T': 'G', 'U': 'H', 'V': 'I', 'W': 'J', 'X': 'K', 
'Y': 'L', 'Z': 'M', 'a': 'n', 'b': 'o', 'c': 'p', 'd': 'q', 'e': 'r', 'f': 's', 
'g': 't', 'h': 'u', 'i': 'v', 'j': 'w', 'k': 'x', 'l': 'y', 'm': 'z', 'n': 'a', 
'o': 'b', 'p': 'c', 'q': 'd', 'r': 'e', 's': 'f', 't': 'g', 'u': 'h', 'v': 'i', 
'w': 'j', 'x': 'k', 'y': 'l', 'z': 'm'}

우리의 문자열은 this.d를 이용해서 번역하는 코드는 다음과 같다.

### 23.py

import this

if __name__=="__main__" :
    src = "va gur snpr bs jung"
    ans = ''.join([this.d[x] for x in src if x!= " "])

출력은 inthefaceof이다. python 원칙에 쓰여있다. in the face of ambiguity

찾았다. ambiguity

Answer Url : http://www.pythonchallenge.com/pc/hex/ambiguity.html