Created
June 25, 2017 10:46
-
-
Save yosangwon/f205654638fd6ad67b287b6ae0b09e92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(first). | |
-export([double/1,mult/2,area/3,treble/1,square/1]). | |
mult(X,Y) -> | |
X*Y. | |
double(X) -> | |
mult(2,X). | |
area(A,B,C) -> | |
S = (A+B+C)/2, | |
math:sqrt(S*(S-A)*(S-B)*(S-C)). | |
treble(A) -> | |
mult(3,A). | |
square(A) -> | |
mult(A,A). | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(second). | |
-export([hypotenuse/2, perimeter/2, area/2]). | |
% import functions from first.erl. I thought I can do this c(first) | |
% but it's erlang intercative shell only! I googled how to import a module | |
% and found this: http://erlang.org/doc/reference_manual/modules.html | |
-import(first, [multi/2, area/3]). | |
% gives the size of the hypotenuse of a right-angled triangle | |
% given the length of two other sizes. | |
hypotenuse(A,B) -> | |
math:sqrt(first:square(A)+first:square(B)). | |
% gives an perimeter of right-angled triangle | |
% given the length of two short sides. | |
perimeter(A,B) -> | |
A+B+hypotenuse(A,B). | |
% gives an area of right-angled triangle | |
% given the length of two short sides. | |
area(A,B) -> | |
first: area(A,B,hypotenuse(A,B)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment