Skip to content
Browse files

a little clean-up

  • Loading branch information...
1 parent cee164a commit e23142d1d36c6fc362bfa0c07bcb0824b611d4a4 @glyphrider committed Nov 19, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 prime.erl
View
3 prime.erl
@@ -9,14 +9,15 @@ prime(N,M) when N == M -> true;
prime(N,M) when N rem M == 0 -> false;
prime(N,M) -> prime(N,M+1).
-prime(1) -> false;
+prime(N) when N < 2 -> false;
prime(N) when N rem 1 == 0 -> prime(N,2).
factors(N,M,L) when N == M -> [M|L];
factors(N,M,L) when N < M -> L;
factors(N,M,L) when N rem M == 0 -> factors(N div M,M,[M|L]);
factors(N,M,L) -> factors(N,M+1,L).
+% list is build in decending order, so reverse it
factors(N) -> lists:reverse(factors(N,2,[])).
-ifdef(EUNIT).

0 comments on commit e23142d

Please sign in to comment.
Something went wrong with that request. Please try again.