Move History

Rooted by: Power of Two
Fork Selected
  • Description

    the test inputs are wrong, because you can check only using the modulus operation, if it was created correctly 30 shouldn't be assign as true, but it only test results from 2 exponentiation

    Code
    def power_of_two( n ):
        if n % 2 == 0: return True
        else: return False
    Test Cases
    from random import randint
    
    for x in range(5):
      n = 2 ** randint( 21, 25 )
      test.assert_equals( power_of_two(n), True )
      
    for x in range(5):
      n = 2 ** randint( 21, 25 )+(-1) ** randint( 1, 4 )
      test.assert_equals( power_of_two(n), False )
  • Code
    • def power_of_two( n ):
    • return n & ( n - 1 ) == 0
    • if n % 2 == 0: return True
    • else: return False