Created
November 6, 2016 11:34
-
-
Save chwnam/3e2df2c282a8d3e8fc24dec9c267db03 to your computer and use it in GitHub Desktop.
멈뭄미의 저주
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| def separate(ch): | |
| unicode_index = ord(ch) - 0xac00 | |
| final = unicode_index % 28 | |
| temp = (unicode_index - final) // 28 | |
| initial, medial = temp // 21, temp % 21 | |
| return initial, medial, final | |
| def build(initial, medial, final): | |
| code = int((((initial * 21) + medial) * 28) + final + 0xac00) | |
| try: | |
| return unichr(code) | |
| except NameError: | |
| return chr(code) | |
| def is_hangul(ch): | |
| return 0xac00 <= ord(ch) <= 0xd7a3 if ch else False | |
| if __name__ == '__main__': | |
| print(separate(u'가')) | |
| print(separate(u'나')) | |
| print(separate(u'홑')) | |
| print(build(11, 0, 21)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from hangul import build, is_hangul, separate | |
| e_idx_beg = 11 | |
| e_idx_fin = 21 | |
| m_idx_beg = 6 | |
| m_idx_fin = 16 | |
| def mmm(ch): | |
| if is_hangul(ch): | |
| separated = separate(ch) | |
| return build( | |
| m_idx_beg if separated[0] == e_idx_beg else separated[0], | |
| separated[1], | |
| m_idx_fin if separated[2] == e_idx_fin else separated[2] | |
| ) | |
| return ch | |
| def mmm_text(text): | |
| return ''.join([mmm(ch) for ch in text]) | |
| if __name__ == '__main__': | |
| text = u'당신은 네모네모 멍뭉이와 눈이 마주치고 말았습니다. 당신은 이제 네모네모 멍뭉이의 저주로 동그란 글자를 칠 수 없습니다. 멍멍!' | |
| print(mmm_text(text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment