Created
September 6, 2012 17:17
-
-
Save joshrotenberg/3658698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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