Skip to content

Instantly share code, notes, and snippets.

@TheEndIsNear
Created May 4, 2020 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheEndIsNear/e0257975c05cc581cef4de9a0934b318 to your computer and use it in GitHub Desktop.
Save TheEndIsNear/e0257975c05cc581cef4de9a0934b318 to your computer and use it in GitHub Desktop.
Solution for the first assignment
-module(first).
-export([double/1,mult/2,area/3,square/1,triple/1]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
triple(X) ->
mult(X, 3).
square(X) ->
mult(X, X).
area(A,B,C) ->
S = (A+B+C)/2,
math:sqrt(S*(S-A)*(S-B)*(S-C)).
-module(second).
-export([hypotenuse/2,perimeter/2,area/2]).
% caluculate the hypotenuse of a right-angled triangle
% C^2 = A^2 + B^2
hypotenuse(A, B) ->
math:sqrt(first:square(A) + first:square(B)).
% calculate the perimeter of a right-angled triangle
% perimeter = A + B + C (hypotenuse(A,B))
perimeter(A, B) ->
A + B + hypotenuse(A, B).
% calculate the area of a right-angled triangle
% area = 1/2 * (A * B)
area(A, B) ->
0.5 * (A * B).
@elbrujohalcon
Copy link

Great solution.
Tip: you can start your documentation comments with @doc to make them visible to edoc, in case you later want to generate HTML docs automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment