Skip to content

Instantly share code, notes, and snippets.

@scollinson
Last active January 4, 2016 02:09
Show Gist options
  • Save scollinson/8553582 to your computer and use it in GitHub Desktop.
Save scollinson/8553582 to your computer and use it in GitHub Desktop.
for a given maximum comparator width, determine a list of comparator stages
MAX_COMPARATOR_WIDTH = 24
def stages(n, max_width=MAX_COMPARATOR_WIDTH):
s = []
while n > 1:
q = n // max_width
r = n % max_width
s.append([max_width]*q + [r])
n += (max_width - 1)
n //= max_width
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment