title: Smallest Power Of 2 Greater Than Or Equal To N 1
signature: func smallestPowerOf2GreaterThanOrEqualToN1(n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(31, 32)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(89, 128)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(92, 128)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(66, 128)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(38, 64)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(34, 64)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(17, 32)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(24, 32)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(54, 64)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(20, 32)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def smallest_power_of_2_greater_than_or_equal_to_n_1(n):
      p = 1
      if (n and (not (n & (n - 1)))):
          return n
      while (p < n):
          p <<= 1
      return p
source_cpp: unsigned int smallest_power_of_2_greater_than_or_equal_to_n_1(unsigned int n) {
    unsigned int p = 1;
    if ( n && ! ( n & ( n - 1 ) ) ) return n;
    while ( p < n ) p <<= 1;
    return p;
  }