Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. """
  4. k_adic.py
  5. """
  6.  
  7. alphabet = lambda n: chr(ord('A') + n - 1)
  8. ALPHABET_LEN = ord('Z') - ord('A') + 1 # 26
  9.  
  10. def k_adic(number, get_digits=alphabet, base=ALPHABET_LEN):
  11. """
  12. k-adic notation A.K.A. Bijective numeration
  13. """
  14.  
  15. result = ''
  16. while number > 0:
  17. number, remainder = divmod(number, base) # 여기까지는 보통의 진법 변환과 같지만,
  18. if remainder == 0: # 나머지의 범위가 1~base(26)이 되도록 조정합니다.
  19. number -= 1 # 나머지가 26이 되었으므로, 피제수도 1을 빼줍니다.
  20. remainder = base
  21. result = get_digits(remainder) + result
  22. return result
Add Comment
Please, Sign In to add comment