Skip to content

Instantly share code, notes, and snippets.

@2torus
Created May 7, 2020 09:00
Show Gist options
  • Save 2torus/3d4bc4f111f8de2247459505f0f38ea7 to your computer and use it in GitHub Desktop.
Save 2torus/3d4bc4f111f8de2247459505f0f38ea7 to your computer and use it in GitHub Desktop.
Programming exercise for "FutureLearn/Programming in Earlang"
-module(first).
-export([double/1, treble/1, square/1,perimeter/3, area/3]).
mult(X, Y) ->
X * Y.
double(X) ->
mult(2,X).
treble(X) ->
mult(3, X).
square(X) ->
mult(X, X).
perimeter(A, B, C) ->
A + B + C.
area(A,B,C) ->
S = perimeter(A, B, C)/2,
math:sqrt(S * (S - A) * (S - B) * (S - C)).
-module(second).
-export([hypot/2, perimeter/2, area/2]).
hypot(A, B) ->
math:sqrt(first:square(A) + first:square(B)).
perimeter(A, B) ->
C = hypot(A, B),
first:perimeter(A, B, C).
area(A, B) ->
C = hypot(A, B),
first:area(A, B, C).
@elbrujohalcon
Copy link

Excellent!

@2torus
Copy link
Author

2torus commented May 7, 2020

Thank you @elbrujohalcon.

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