Created
February 18, 2015 17:20
-
-
Save sasa1977/98e6465bf854a9d86cba 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 Prime do | |
| def prime_factors(number) do | |
| first_divisor = | |
| div(number, 2)..1 | |
| |> Enum.find(&(rem(number, &1) == 0)) | |
| case first_divisor do | |
| 1 -> [number] | |
| _ -> prime_factors(div(number, first_divisor)) ++ prime_factors(first_divisor) | |
| end | |
| |> Enum.uniq | |
| end | |
| end | |
| input = hd(System.argv) | |
| number = String.strip(input) |> String.to_integer | |
| IO.puts "Prime factors of #{number} are #{inspect Prime.prime_factors(number)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment