Skip to content

Instantly share code, notes, and snippets.

@adam-e-trepanier
Created October 21, 2013 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-e-trepanier/7091249 to your computer and use it in GitHub Desktop.
Save adam-e-trepanier/7091249 to your computer and use it in GitHub Desktop.
-module(math_functions).
-export([test/0, even/1, odd/1, filter/2, split/1, split2/1]).
test() ->
true = even(10),
false = even(11),
true = odd(11),
false = odd(10),
tests_passed.
even(N) ->
if
N rem 2 =:= 0 ->
true;
true -> false
end.
odd(N) ->
if
N rem 2 =:= 0 ->
false;
true -> true
end.
filter(F, L) ->
[X || X <- L, F(X) =:= true].
split(L) ->
{[X || X <- L, even(X)],
[Y || Y <- L, odd(Y)]}.
split2(L) ->
[{X, Y} || X <- filter(even, L),
Y <- filter(odd, L)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment