Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def build(num, probs):
  2.     probs = sorted(probs)
  3.     res = []
  4.     if num == 1:
  5.         index = probs[0][1]
  6.         res.append(('', index))
  7.     if num >= 2:
  8.         first = probs[0]
  9.         second = probs[1]
  10.         probs[1] = (first[0] + second[0], second[1])
  11.         for i in build(num - 1, probs[1:]):
  12.             res.append(i)
  13.         for i in res:
  14.             if i[1] == probs[1][1]:
  15.                 ans = i
  16.                 res.append((ans[0] + '0', first[1]))
  17.                 res.append((ans[0] + '1', second[1]))
  18.                 res.remove(ans)
  19.                 break
  20.     return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement