Skip to content

Instantly share code, notes, and snippets.

@tomoya55
Created June 14, 2009 06:35
Show Gist options
  • Select an option

  • Save tomoya55/129574 to your computer and use it in GitHub Desktop.

Select an option

Save tomoya55/129574 to your computer and use it in GitHub Desktop.
-module(recursion).
-export([bump/1, average/1, even_only/1]).
bump([]) ->
[];
bump([H|T]) ->
[H + 1 | bump(T)].
average(L) ->
sum(L) / length(L).
sum([]) ->
0;
sum([H|T]) -> H + sum(T).
even_only([]) ->
[];
even_only([H|T]) when H rem 2 == 0 -> [H | even_only(T)];
even_only([_|T]) -> even_only(T).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment