Last active
March 24, 2017 12:24
-
-
Save pichi/1b8b11552266451da64daf4d720227a5 to your computer and use it in GitHub Desktop.
Rock, paper, scissors game definition
This file contains 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(rps). | |
-export([beats/1]). | |
-export([result/2]). | |
-export([tournament/2]). | |
beats(rock) -> scissors; | |
beats(paper) -> rock; | |
beats(scissors) -> paper. | |
result(X, Y) -> | |
case {beats(X), beats(Y)} of | |
{Y, _} -> win; | |
{_, X} -> lose; | |
_ -> draw | |
end. | |
points(X, Y) -> | |
result2points(result(X, Y)). | |
result2points(win) -> 1; | |
result2points(draw) -> 0; | |
result2points(lose) -> -1. | |
tournament(L1, L2) -> | |
lists:sum(lists:zipwith(fun points/2, L1, L2)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment