title: Steins Algorithm For Finding Gcd 1
signature: def steinsAlgorithmForFindingGcd1(a: Int, b: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(a: Int, b: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(a, b),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        52, 29, 
        1    
      )}")   
  
  
      println(s"TEST-1...${driver(
        36, 94, 
        2    
      )}")   
  
  
      println(s"TEST-2...${driver(
        12, 6, 
        6    
      )}")   
  
  
      println(s"TEST-3...${driver(
        69, 7, 
        1    
      )}")   
  
  
      println(s"TEST-4...${driver(
        45, 11, 
        1    
      )}")   
  
  
      println(s"TEST-5...${driver(
        7, 51, 
        1    
      )}")   
  
  
      println(s"TEST-6...${driver(
        45, 55, 
        5    
      )}")   
  
  
      println(s"TEST-7...${driver(
        62, 86, 
        2    
      )}")   
  
  
      println(s"TEST-8...${driver(
        96, 63, 
        3    
      )}")   
  
  
      println(s"TEST-9...${driver(
        89, 12, 
        1    
      )}")   
  
  }
  
source_py: def steins_algorithm_for_finding_gcd_1(a, b):
      if (a == b):
          return a
      if (a == 0):
          return b
      if (b == 0):
          return a
      if (((~ a) & 1) == 1):
          if ((b & 1) == 1):
              return steins_algorithm_for_finding_gcd_1((a >> 1), b)
          else:
              return (steins_algorithm_for_finding_gcd_1((a >> 1), (b >> 1)) << 1)
      if (((~ b) & 1) == 1):
          return steins_algorithm_for_finding_gcd_1(a, (b >> 1))
      if (a > b):
          return steins_algorithm_for_finding_gcd_1(((a - b) >> 1), b)
      return steins_algorithm_for_finding_gcd_1(((b - a) >> 1), a)
source_cpp: int steins_algorithm_for_finding_gcd_1(int a, int b) {
    if ( a == b ) return a;
    if ( a == 0 ) return b;
    if ( b == 0 ) return a;
    if ( ~ a & 1 ) {
      if ( b & 1 ) return steins_algorithm_for_finding_gcd_1 ( a >> 1, b );
      else return steins_algorithm_for_finding_gcd_1 ( a >> 1, b >> 1 ) << 1;
    }
    if ( ~ b & 1 ) return steins_algorithm_for_finding_gcd_1 ( a, b >> 1 );
    if ( a > b ) return steins_algorithm_for_finding_gcd_1 ( ( a - b ) >> 1, b );
    return steins_algorithm_for_finding_gcd_1 ( ( b - a ) >> 1, a );
  }