MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / check_partition_perfect

Function check_partition_perfect

project_euler/problem_207/sol1.py:44–60  ·  view source on GitHub ↗

Check if t = f(positive_integer) = log2(sqrt(4*positive_integer+1)/2 + 1/2) is a real number. >>> check_partition_perfect(2) True >>> check_partition_perfect(6) False

(positive_integer: int)

Source from the content-addressed store, hash-verified

42
43
44def check_partition_perfect(positive_integer: int) -> bool:
45 """
46
47 Check if t = f(positive_integer) = log2(sqrt(4*positive_integer+1)/2 + 1/2) is a
48 real number.
49
50 >>> check_partition_perfect(2)
51 True
52
53 >>> check_partition_perfect(6)
54 False
55
56 """
57
58 exponent = math.log2(math.sqrt(4 * positive_integer + 1) / 2 + 1 / 2)
59
60 return exponent == int(exponent)
61
62
63def solution(max_proportion: float = 1 / 12345) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected