Skip to content

Instantly share code, notes, and snippets.

@danielribes
Created May 5, 2020 19:34
Show Gist options
  • Save danielribes/4b13c28b3d1b3da8eccdfc16cb9cc03e to your computer and use it in GitHub Desktop.
Save danielribes/4b13c28b3d1b3da8eccdfc16cb9cc03e to your computer and use it in GitHub Desktop.
Functional Programming in Erlang The University of Kent - Activity 1.9, second module
%%
%% second.erl
%% - Functional Programming in Erlang
%% Activity 1.9
%%
%% Daniel Ribes
%%
-module(second).
-export([hypotenuse/2, perimeter/2, perimeter/3, area/2]).
%%
%% Hypotenuse of a right-angled triangle
%%
hypotenuse(A, B) ->
H = first:square(A) + first:square(B),
math:sqrt(H).
%%
%% Area of a right-angled triangle
%%
area(A, B) ->
B * A / 2.
%%
%% Perimeter of a right-angled triangle
%%
%% - without knowing Hypotenuse
perimeter(A, B) ->
A + B + hypotenuse(A, B).
%% - with Hypotenuse
perimeter(A, B, H) ->
A + B + H.
@elbrujohalcon
Copy link

This is perfect! The use of the helper function perimeter/3 is a nice touch. On the other hand, since that one is just a helper, you don't really need to export it.

@danielribes
Copy link
Author

danielribes commented May 6, 2020

Thanks!

On the other hand, since that one is just a helper, you don't really need to export it.

Ah, ok! :)

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