Advertisement
Guest User

Radix N Base

a guest
Feb 23rd, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. from math import log
  2.  
  3. inp = [53, 89, 150, 36, 633, 233]          # lista of int
  4. BASE = 255                                  # baza in care vrei sa sortezi
  5. # simplu digit calculator in functie de baza
  6. digits = (int(log(max(inp), BASE)) + 1)
  7.  
  8.  
  9. def setup():
  10.     d = {}
  11.     for i in range(BASE):
  12.         d[i] = []
  13.     return d
  14.  
  15.  
  16. def dicToList(d):
  17.     l = []
  18.     for values in d.values():
  19.         for value in values:
  20.             l.append(value)
  21.     return l
  22.  
  23.  
  24. if __name__ == "__main__":
  25.     key = 1 # adica cifra unitatilor (abcd // key = d)
  26.     for _ in range(digits):
  27.         d = setup()
  28.         for i in inp:
  29.             d[(i//key) % BASE].append(i)
  30.         inp = dicToList(d)
  31.         key *= BASE
  32.     print(inp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement