Last active
May 11, 2020 16:28
-
-
Save bladebhs/3a1b7234e8507e05e8dfd20a1a781625 to your computer and use it in GitHub Desktop.
My first Erlang program. Functional Programming in Erlang course
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) -> | |
X * X. | |
treble(X) -> | |
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) -> | |
math:sqrt(first:square(A) + first:square(B)). | |
perimeter(A, B) -> | |
A + B + hypotenuse(A, B). | |
area(A, B) -> | |
A * B / 2. |
Excellent! But if you're going to use
first:mult/2
to multiply… you should go all the way and use it to multiply by1/2
, too ;)
Yeah, it's weird :) mult
function is useless. Fixed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent! But if you're going to use
first:mult/2
to multiply… you should go all the way and use it to multiply by1/2
, too ;)