Skip to content

Instantly share code, notes, and snippets.

@apbarrero
Created June 21, 2017 20:17
Show Gist options
  • Save apbarrero/bc73b214db3810b1c0d29875bd8bbe23 to your computer and use it in GitHub Desktop.
Save apbarrero/bc73b214db3810b1c0d29875bd8bbe23 to your computer and use it in GitHub Desktop.
First erlang program
-module(first).
-export([double/1,mult/2,area/3,sq/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)).
sq(X) ->
mult(X,X).
treble(X) ->
mult(X,3).
-module(second).
-import(first, [sq/1, mult/2]).
-export([hypotenuse/2, perimeter/2, area/2]).
hypotenuse(A,B) ->
S = first:sq(A) + first:sq(B),
math:sqrt(S).
perimeter(A,B) ->
A + B + hypotenuse(A, B).
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