Updating PE.

This commit is contained in:
Kyle Isom 2019-04-22 07:01:00 -07:00
parent ba841f127c
commit 8450ce8753
2 changed files with 26 additions and 1 deletions

15
pe/geometry1.erl Normal file
View File

@ -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.

View File

@ -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).