Skip to content

Instantly share code, notes, and snippets.

@bladebhs
Last active May 11, 2020 16:28
Show Gist options
  • Save bladebhs/3a1b7234e8507e05e8dfd20a1a781625 to your computer and use it in GitHub Desktop.
Save bladebhs/3a1b7234e8507e05e8dfd20a1a781625 to your computer and use it in GitHub Desktop.
My first Erlang program. Functional Programming in Erlang course
-module(first).
-export([double/1, mult/2, area/3, square/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)).
square(X) ->
X * X.
treble(X) ->
3 * X.
-module(second).
-export([hypotenuse/2, perimeter/2, area/2]).
hypotenuse(A, B) ->
math:sqrt(first:square(A) + first:square(B)).
perimeter(A, B) ->
A + B + hypotenuse(A, B).
area(A, B) ->
A * B / 2.
@elbrujohalcon
Copy link

Excellent! But if you're going to use first:mult/2 to multiply… you should go all the way and use it to multiply by 1/2, too ;)

@bladebhs
Copy link
Author

Excellent! But if you're going to use first:mult/2 to multiply… you should go all the way and use it to multiply by 1/2, too ;)

Yeah, it's weird :) mult function is useless. Fixed

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