Updating PE.
This commit is contained in:
		
							parent
							
								
									ba841f127c
								
							
						
					
					
						commit
						8450ce8753
					
				| 
						 | 
					@ -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.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								pe/shop.erl
								
								
								
								
							
							
						
						
									
										12
									
								
								pe/shop.erl
								
								
								
								
							| 
						 | 
					@ -1,4 +1,14 @@
 | 
				
			||||||
-module(shop).
 | 
					-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).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue