Skip to content

Instantly share code, notes, and snippets.

@gfredtech
Created February 10, 2018 20:18
Show Gist options
  • Select an option

  • Save gfredtech/30daa57d9c1165ee47fd04737aacb824 to your computer and use it in GitHub Desktop.

Select an option

Save gfredtech/30daa57d9c1165ee47fd04737aacb824 to your computer and use it in GitHub Desktop.
def is_power_of_2(num):
if num < 2:
return False
power = int(math.log(num, 2) + 0.5)
return 2 ** power == num
def func(x, y):
maxx = max(len(x), len(y))
if len(x) == len(y) and is_power_of_2(len(x)):
return x, y
while not is_power_of_2(maxx):
maxx += 1
return ([0] * (maxx - len(x))) + x, ([0] * (maxx - len(y))) + y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment