Skip to content

Instantly share code, notes, and snippets.

@ziozzang
Last active December 26, 2015 00:29
Show Gist options
  • Save ziozzang/7064713 to your computer and use it in GitHub Desktop.
Save ziozzang/7064713 to your computer and use it in GitHub Desktop.
http://www.synapsoft.co.kr/jsp/recruit/13_apply.html 사이냅 소프트쪽의 테스트 코드를 파이썬으로 얼마나 짧게 짤 수 있을까 해서 만든 코드 사실 C/C++ 로 짜도 그게 그거...
#!/usr/bin/python
# - Code by Jioh L. Jung -
# - ziozzang@gmail.com
#
# Python Code for synapsoft test. / just for fun.! yeah!
# http://www.synapsoft.co.kr/jsp/recruit/13_apply.html
#
def c(n,s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
return (((n-1) < 26) and s[n-1]) or (c((n-1) // 26) + s[(n-1) % 26])
"""
Example
>>> c(1)
'A'
>>> c(26)
'Z'
>>> c(27)
'AA'
>>> c(28)
'AB'
>>> c(52)
'AZ'
>>> c(53)
'BA'
"""
@ziozzang
Copy link
Author

  • 핵심은, A가 0이 아니고 1이라는 점 (1부터 시작한다)
  • A=1, AA=27 즉, 0이 일반적으로 플레이스 홀더(또는 패딩)이 되어야 하는데 A는 그런 역할이 아님.
  • 이거 10분만에 손코딩으로 풀어봐라 라고 하면 함정 빠질 사람이 꽤 될텐데. 그거 아니면 뭐.

빈칸 없애고, s를 chr(64+n) 함수로 바꾸면 더 줄어 들듯.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment