title: Steins Algorithm For Finding Gcd 1
signature: function steinsAlgorithmForFindingGcd1(a: number, b: number): number {
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 );
  }
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"a": 52, "b": 29}}, {"idx": 1, "outputs": 2, "inputs": {"a": 36, "b": 94}}, {"idx": 2, "outputs": 6, "inputs": {"a": 12, "b": 6}}, {"idx": 3, "outputs": 1, "inputs": {"a": 69, "b": 7}}, {"idx": 4, "outputs": 1, "inputs": {"a": 45, "b": 11}}, {"idx": 5, "outputs": 1, "inputs": {"a": 7, "b": 51}}, {"idx": 6, "outputs": 5, "inputs": {"a": 45, "b": 55}}, {"idx": 7, "outputs": 2, "inputs": {"a": 62, "b": 86}}, {"idx": 8, "outputs": 3, "inputs": {"a": 96, "b": 63}}, {"idx": 9, "outputs": 1, "inputs": {"a": 89, "b": 12}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(a: number, b: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(a, b),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(52, 29, 1);
    console.log(`TEST-0...${result}`);
  
    result = driver(36, 94, 2);
    console.log(`TEST-1...${result}`);
  
    result = driver(12, 6, 6);
    console.log(`TEST-2...${result}`);
  
    result = driver(69, 7, 1);
    console.log(`TEST-3...${result}`);
  
    result = driver(45, 11, 1);
    console.log(`TEST-4...${result}`);
  
    result = driver(7, 51, 1);
    console.log(`TEST-5...${result}`);
  
    result = driver(45, 55, 5);
    console.log(`TEST-6...${result}`);
  
    result = driver(62, 86, 2);
    console.log(`TEST-7...${result}`);
  
    result = driver(96, 63, 3);
    console.log(`TEST-8...${result}`);
  
    result = driver(89, 12, 1);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: steinsAlgorithmForFindingGcd1
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js