Last active
May 6, 2020 06:35
-
-
Save gorkaio/fa82e905f7c8e4dcfe9bfdfad6f1111d to your computer and use it in GitHub Desktop.
First steps in Erlang
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,treble/1,square/1,mult/2,area/3]). | |
mult(X,Y) -> | |
X*Y. | |
double(X) -> | |
mult(2,X). | |
treble(X) -> | |
mult(3,X). | |
square(X) -> | |
mult(X,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) -> | |
H2 =first:square(A)+first:square(B), | |
math:sqrt(H2). | |
perimeter(A,B) -> | |
H =hypotenuse(A,B), | |
H+A+B. | |
area(A,B) -> | |
B*A/2. |
Thanks! Baby steps, but I'm loving the Erlang simplicity :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job!