diff --git a/pe/geometry1.erl b/pe/geometry1.erl new file mode 100644 index 0000000..3bb5571 --- /dev/null +++ b/pe/geometry1.erl @@ -0,0 +1,15 @@ +-module(geometry1). +-export([test/0, area/1]). + +test() -> + 12 = area({rectangle, 3, 4}), + 144 = area({square, 12}), + tests_worked. +area({rectangle, Width, Height}) -> + Width * Height; +area({circle, Radius}) -> + 3.14159 * Radius * Radius; +area({square, Side}) -> + Side * Side. + + diff --git a/pe/shop.erl b/pe/shop.erl index 6b43a66..1de2da4 100644 --- a/pe/shop.erl +++ b/pe/shop.erl @@ -1,4 +1,14 @@ -module(shop). --export([cost/1]). +-export([cost/1, total/1]). +%% ShoppingList = [{oranges,4},{newspaper,1},{apples,10},{pears,6},{milk,3}] +cost (oranges) -> 5; +cost (newspaper) -> 8; +cost (apples) -> 2; +cost (pears) -> 9; +cost (milk) -> 7. +total([]) -> + 0; +total([{Item, Count}|Rest]) -> + cost(Item) * Count + total(Rest).