# Computing the GCD

# Computing the GCD

nano + 0 comments Here is a templete I wrote to handle input/output in OCaml because I had difficulty without any templete in OCaml, while a templete for Scala is provided.

I hope this might be of some help for OCaml users. If you find any mistakes or anything to rewrite, please let me know.

let rec intlst_of_strlst lst = match lst with first::rest -> int_of_string(first)::intlst_of_strlst(rest) | [] -> [] let () = let str = read_line() in let lst = Str.split (Str.regexp "[ \t]+") str in let d = intlst_of_strlst lst in let xy = Array.of_list d in let ans = gcd xy.(0) xy.(1) in print_int ans;;

mizgajski_jan + 1 comment It would be amazing if you guys could add a post submission leaderboard of solutions curated by the community. Check out how codewars do it. This feature has much more use for pro programmers than the challenges themselves - you are able to learn new constructs and approaches by example on something you have solved yourselve and understand the premises of.

For example, when solving the fibonacii challenge (very basic), I would love to see if someone used the

`@tailrec`

annotation in Scala, or how they implemented the accumulator technique and downloading every solution separatly is a real drag. The value of community curated leaderboard of solutions increseas exponentialy as the complexity of the challenge increases.abhiranjan + 1 comment Yes. Actually similar feature is in pipeline where users will moderate the ordering of submissions at leaderboard.

aminoacid + 0 comments Still waiting for it to be implemented..

shailrshah + 0 comments Here's my one-line solution:

int getGCD(int a, int b) { return (a == 0 || b == 0) ? (a + b) : (getGCD(b, a % b)); }

mrussotto + 0 comments Haskell wiseacre answer:

gcd' = gcd

andrewboy72618 + 0 comments my Haskell solution

gcd' :: Integral a => a -> a -> a gcd' n 0 = n gcd' n m = gcd m (n `mod` m)

Sort 44 Discussions, By:

Please Login in order to post a comment