Skip to content

Instantly share code, notes, and snippets.

@Yuri-M-Dias
Created June 22, 2017 02:48
Show Gist options
  • Save Yuri-M-Dias/25bcd721e02ad039b265300557980a40 to your computer and use it in GitHub Desktop.
Save Yuri-M-Dias/25bcd721e02ad039b265300557980a40 to your computer and use it in GitHub Desktop.
FutureLearn - Erlang - 1.9
-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).
-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