MCPcopy Create free account
hub / github.com/ActiveState/code / calculate

Method calculate

recipes/Python/577475_Power_Of_Two/recipe-577475.py:41–53  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

39 # calculating the power of two
40 @staticmethod
41 def calculate(n):
42 digits = [1]
43
44 # little performance improvement
45 for k in [3, 2]:
46 if n > 2**k:
47 PowerOfTwo.calculateDigits(digits, n // k, 2**k)
48 n %= k
49
50 if n > 0:
51 PowerOfTwo.calculateDigits(digits, n, 2)
52 digits.reverse()
53 return digits
54
55 @staticmethod
56 def dump(digits, digitsPerRow = 50):

Callers 2

QueenFunction · 0.45
mainFunction · 0.45

Calls 2

calculateDigitsMethod · 0.80
reverseMethod · 0.45

Tested by

no test coverage detected