Advertisement
here2share

# z_fast_trinary_string.py

Dec 21st, 2021
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. # z_fast_trinary_string.py
  2.  
  3. def str2base(b,s):
  4.     n = int(s, b)+1
  5.     L = len(s)
  6.     if n == 0:
  7.         return 0
  8.     digits = []
  9.     while n:
  10.         digits.append(int(n % b))
  11.         n //= b
  12.     if len(digits) > L:
  13.         return ''
  14.     return ''.join(map(str, digits[::-1])).zfill(L)
  15.  
  16. s = '0'*5
  17. while s:
  18.     print s,
  19.     s = str2base(3,s)
  20.    
  21. '''
  22. 00000 00001 00002 00010 00011 00012 00020 00021 00022 00100 00101 00102 00110 00111 00112 00120 00121 00122 00200 00201 00202 00210 00211 00212 00220 00221 00222 01000 01001 01002 01010 01011 01012 01020 01021 01022 01100 01101 01102 01110 01111 01112 01120 01121 01122 01200 01201 01202 01210 01211 01212 01220 01221 01222 02000 02001 02002 02010 02011 02012 02020 02021 02022 02100 02101 02102 02110 02111 02112 02120 02121 02122 02200 02201 02202 02210 02211 02212 02220 02221 02222 10000 10001 10002 10010 10011 10012 10020 10021 10022 10100 10101 10102 10110 10111 10112 10120 10121 10122 10200 10201 10202 10210 10211 10212 10220 10221 10222 11000 11001 11002 11010 11011 11012 11020 11021 11022 11100 11101 11102 11110 11111 11112 11120 11121 11122 11200 11201 11202 11210 11211 11212 11220 11221 11222 12000 12001 12002 12010 12011 12012 12020 12021 12022 12100 12101 12102 12110 12111 12112 12120 12121 12122 12200 12201 12202 12210 12211 12212 12220 12221 12222 20000 20001 20002 20010 20011 20012 20020 20021 20022 20100 20101 20102 20110 20111 20112 20120 20121 20122 20200 20201 20202 20210 20211 20212 20220 20221 20222 21000 21001 21002 21010 21011 21012 21020 21021 21022 21100 21101 21102 21110 21111 21112 21120 21121 21122 21200 21201 21202 21210 21211 21212 21220 21221 21222 22000 22001 22002 22010 22011 22012 22020 22021 22022 22100 22101 22102 22110 22111 22112 22120 22121 22122 22200 22201 22202 22210 22211 22212 22220 22221 22222
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement