Last active
March 3, 2017 15:35
-
-
Save randomecho/d2cdfd854a4e9d5947707eedf19fee30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(patterns). | |
-export([exxor/2,exxot/2,exxon/2,efix/2,maxThree/3,howManyEqual/3]). | |
exxor(X,Y) -> | |
X =/= Y. | |
exxot(X,Y) -> | |
X == Y. | |
exxon(X,Y) -> | |
not (X == Y). | |
efix(X,Y) -> | |
(X == Y) and (X > Y). | |
maxThree(X,Y,Z) -> | |
max(max(X,Y),Z). | |
howManyEqual(X,X,X) -> 3; | |
howManyEqual(X,X,_) -> 2; | |
howManyEqual(X,_,X) -> 2; | |
howManyEqual(_,X,X) -> 2; | |
howManyEqual(_,_,_) -> 0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(recursion). | |
-export([fib/1,pieces/1]). | |
fib(1) -> | |
1; | |
fib(2) -> | |
1; | |
fib(X) when X > 0 -> | |
fib(X-1) + fib(X-2). | |
pieces(1) -> | |
2; | |
pieces(X) when X > 0 -> | |
pieces(X-1) + X. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment