Last active
May 6, 2020 09:43
-
-
Save jameswalton/c3e40af631c442aa4c03768e73f7945c to your computer and use it in GitHub Desktop.
Functional programming in Erlang course
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. | |
square(X) -> | |
mult(X,X). | |
treble(X) -> | |
mult(3,X). | |
double(X) -> | |
mult(2,X). | |
area(A, B, C) -> | |
S = (A+B+C)/2, | |
math:sqrt(S*(S-A)*(S-B)*(S-C)). |
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]). | |
hypotenuse(A,B) -> | |
AB = first:square(A) + first:square(B), | |
math:sqrt(AB). | |
%% Perimeter of a right-angled triangle | |
perimeter(A,B) -> | |
A+B+(hypotenuse(A,B)). | |
%% Area of a right-angled triangle | |
area(A,B) -> A*B/2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment