Advertisement
here2share

# proper_base3.py

Sep 17th, 2020 (edited)
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. # proper_base3.py
  2.  
  3. def base3(n):
  4.     if n == 0:
  5.         return [0]
  6.     nums = []
  7.     one = False
  8.     if n == 1:
  9.         one = 1
  10.     while n:
  11.         r = n % 3
  12.         n /= 3
  13.         if (n,r) == (0,1) and not one:
  14.             r = 0
  15.         nums.append(int(r))
  16.     return nums[::-1]
  17. 0
  18. i = 0
  19. o = int('2'*4,3)+1
  20. while i < o:
  21.     print i, '\t', base3(i)
  22.     i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement