title: Steins Algorithm For Finding Gcd 1
signature: function steins_algorithm_for_finding_gcd_1(a, b)
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.entry_fn_name: steins_algorithm_for_finding_gcd_1
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(a, b, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, b) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(52, 29, 1)
      print(string.format("TEST-0...%s",result))
  
      result = driver(36, 94, 2)
      print(string.format("TEST-1...%s",result))
  
      result = driver(12, 6, 6)
      print(string.format("TEST-2...%s",result))
  
      result = driver(69, 7, 1)
      print(string.format("TEST-3...%s",result))
  
      result = driver(45, 11, 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver(7, 51, 1)
      print(string.format("TEST-5...%s",result))
  
      result = driver(45, 55, 5)
      print(string.format("TEST-6...%s",result))
  
      result = driver(62, 86, 2)
      print(string.format("TEST-7...%s",result))
  
      result = driver(96, 63, 3)
      print(string.format("TEST-8...%s",result))
  
      result = driver(89, 12, 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
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}}]