title: Steins Algorithm For Finding Gcd 1
signature: steinsAlgorithmForFindingGcd1 :: Integer -> Integer -> Integer
  steinsAlgorithmForFindingGcd1 a b = 
test_code: import Text.Printf
  import Control.Exception (catch, SomeException)
  import Data.Typeable
  import qualified Data.List as List
  import qualified Data.Map as Map
  import qualified Data.Set as Set
  
  -- SOLUTION CODE
  -- ============================================
  
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  validateSolution :: Integer -> Integer -> Bool
  validateSolution actual expected = do
      actual == expected
  
  
  driver :: Integer -> Integer -> Integer -> String
  driver a b expected = do
      if (validateSolution (PLACEHOLDER_FN_NAME a b) expected)
          then "PASSED"
      else "FAILED"
  
  main = do
      printf "TEST-0...%s\n" (driver (52) (29) (1) )
  
      printf "TEST-1...%s\n" (driver (36) (94) (2) )
  
      printf "TEST-2...%s\n" (driver (12) (6) (6) )
  
      printf "TEST-3...%s\n" (driver (69) (7) (1) )
  
      printf "TEST-4...%s\n" (driver (45) (11) (1) )
  
      printf "TEST-5...%s\n" (driver (7) (51) (1) )
  
      printf "TEST-6...%s\n" (driver (45) (55) (5) )
  
      printf "TEST-7...%s\n" (driver (62) (86) (2) )
  
      printf "TEST-8...%s\n" (driver (96) (63) (3) )
  
      printf "TEST-9...%s\n" (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 );
  }