Skip to content

Instantly share code, notes, and snippets.

@fujimura
Created January 12, 2011 11:07
Show Gist options
  • Save fujimura/776021 to your computer and use it in GitHub Desktop.
Save fujimura/776021 to your computer and use it in GitHub Desktop.
7L7W, erlang, day2.
-module(my).
-export([wordnum/1]).
-export([count_to_10/0]).
-export([value_at/2]).
-export([checkout/1]).
wordnum([]) -> 0;
wordnum(W) -> [_|Tail] = W, wordnum(Tail) + 1.
count_to_10() ->
Count_to = fun(_, Limit, Limit) -> io:fwrite("~p~n", [Limit]);
(F, Limit, 0) -> io:fwrite("~p~n", [0]), F(F, Limit, 1);
(F, Limit, Current) -> io:fwrite("~p~n", [Current]), F(F, Limit, Current + 1)
end,
Count_to(Count_to, 10, 0).
value_at(_, []) -> "not found";
value_at(Val, List) ->
[{K, V}|Rest] = List,
case K of
Val -> V;
_ -> value_at(Val, Rest)
end.
checkout([]) -> [];
checkout(List) ->
[{Item, Quantity, Price}|Rest] = List,
[{Item, Quantity*Price}|checkout(Rest)].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment