title: Steins Algorithm For Finding Gcd 1
signature: fun steinsAlgorithmForFindingGcd1(a: Int, b: Int): Int {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(a: Int, b: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(52, 29, 1)
      println("TEST-0...${result}")
      
      result = driver(36, 94, 2)
      println("TEST-1...${result}")
      
      result = driver(12, 6, 6)
      println("TEST-2...${result}")
      
      result = driver(69, 7, 1)
      println("TEST-3...${result}")
      
      result = driver(45, 11, 1)
      println("TEST-4...${result}")
      
      result = driver(7, 51, 1)
      println("TEST-5...${result}")
      
      result = driver(45, 55, 5)
      println("TEST-6...${result}")
      
      result = driver(62, 86, 2)
      println("TEST-7...${result}")
      
      result = driver(96, 63, 3)
      println("TEST-8...${result}")
      
      result = driver(89, 12, 1)
      println("TEST-9...${result}")
      
          
  }
  
  main()
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 );
  }