Skip to content

Instantly share code, notes, and snippets.

@yosangwon
Created June 25, 2017 10:46
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 yosangwon/f205654638fd6ad67b287b6ae0b09e92 to your computer and use it in GitHub Desktop.
Save yosangwon/f205654638fd6ad67b287b6ae0b09e92 to your computer and use it in GitHub Desktop.
-module(first).
-export([double/1,mult/2,area/3,treble/1,square/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)).
treble(A) ->
mult(3,A).
square(A) ->
mult(A,A).
-module(second).
-export([hypotenuse/2, perimeter/2, area/2]).
% import functions from first.erl. I thought I can do this c(first)
% but it's erlang intercative shell only! I googled how to import a module
% and found this: http://erlang.org/doc/reference_manual/modules.html
-import(first, [multi/2, area/3]).
% gives the size of the hypotenuse of a right-angled triangle
% given the length of two other sizes.
hypotenuse(A,B) ->
math:sqrt(first:square(A)+first:square(B)).
% gives an perimeter of right-angled triangle
% given the length of two short sides.
perimeter(A,B) ->
A+B+hypotenuse(A,B).
% gives an area of right-angled triangle
% given the length of two short sides.
area(A,B) ->
first: area(A,B,hypotenuse(A,B)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment