Created
June 22, 2017 02:48
-
-
Save Yuri-M-Dias/25bcd721e02ad039b265300557980a40 to your computer and use it in GitHub Desktop.
FutureLearn - Erlang - 1.9
This file contains 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, | |
square/1, | |
treble/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)). | |
square(X) -> | |
mult(X,X). | |
% Meaning "triple" for british people, learned a new word! | |
treble(X) -> | |
mult(3,X). |
This file contains 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 | |
] | |
). | |
hypotenuse(A,B) -> | |
SUM = first:square(A) + first:square(B), | |
math:sqrt(SUM). | |
perimeter(A,B) -> | |
C = hypotenuse(A,B), | |
A + B + C. | |
area(A,B) -> | |
first:mult(A,B) / 2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment