title: Steins Algorithm For Finding Gcd 1
signature: pub fn steins_algorithm_for_finding_gcd_1(a: i32, b: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(a: i32, b: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(a, b), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        52, 29, 
        1
      ));
      
      println!("TEST-1...{}", driver(
        36, 94, 
        2
      ));
      
      println!("TEST-2...{}", driver(
        12, 6, 
        6
      ));
      
      println!("TEST-3...{}", driver(
        69, 7, 
        1
      ));
      
      println!("TEST-4...{}", driver(
        45, 11, 
        1
      ));
      
      println!("TEST-5...{}", driver(
        7, 51, 
        1
      ));
      
      println!("TEST-6...{}", driver(
        45, 55, 
        5
      ));
      
      println!("TEST-7...{}", driver(
        62, 86, 
        2
      ));
      
      println!("TEST-8...{}", driver(
        96, 63, 
        3
      ));
      
      println!("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 );
  }