spacepaste

  1.  
  2. import itertools
  3. import math
  4. def is_power_of_two_log(n):
  5. if n <= 0:
  6. return False
  7. power = round(math.log(n, 2))
  8. return 2 ** power == n
  9. def is_power_of_two_bitwise(n):
  10. count = 0
  11. while n and count <= 1:
  12. if n & 0b1:
  13. count += 1
  14. n >>= 1
  15. return not count != 1
  16. for n in itertools.count():
  17. r1 = is_power_of_two_log(n)
  18. r2 = is_power_of_two_bitwise(n)
  19. if r1 != r2:
  20. print '%d is inconsistent' % n
  21.