Skip to content

Instantly share code, notes, and snippets.

@gorkaio
Last active May 6, 2020 06:35
Show Gist options
  • Save gorkaio/fa82e905f7c8e4dcfe9bfdfad6f1111d to your computer and use it in GitHub Desktop.
Save gorkaio/fa82e905f7c8e4dcfe9bfdfad6f1111d to your computer and use it in GitHub Desktop.
First steps in Erlang
-module(first).
-export([double/1,treble/1,square/1,mult/2,area/3]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
treble(X) ->
mult(3,X).
square(X) ->
mult(X,X).
area(A,B,C) ->
S = (A+B+C)/2,
math:sqrt(S*(S-A)*(S-B)*(S-C)).
-module(second).
-export([hypotenuse/2,perimeter/2,area/2]).
hypotenuse(A,B) ->
H2 =first:square(A)+first:square(B),
math:sqrt(H2).
perimeter(A,B) ->
H =hypotenuse(A,B),
H+A+B.
area(A,B) ->
B*A/2.
@elbrujohalcon
Copy link

Good job!

@gorkaio
Copy link
Author

gorkaio commented May 6, 2020

Thanks! Baby steps, but I'm loving the Erlang simplicity :)

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