Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Created September 6, 2012 17:17
Show Gist options
  • Select an option

  • Save joshrotenberg/3658698 to your computer and use it in GitHub Desktop.

Select an option

Save joshrotenberg/3658698 to your computer and use it in GitHub Desktop.
defmodule Math.GCD do
@moduledoc "Functions for finding the Greatest Common Denominator"
@doc "Given two numbers, find their GCD"
def gcd(a, b) do
gcd b, rem a, b
end
@doc "Given a list of numbers, find their GCD."
def gcd(l) do
List.foldl l, 0, fn(x,y) -> gcd(x, y) end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment