Skip to content

Instantly share code, notes, and snippets.

@adhalanay
Created May 27, 2020 10:11
Show Gist options
  • Save adhalanay/333a16835bef7b71ac1e03072ffa73f8 to your computer and use it in GitHub Desktop.
Save adhalanay/333a16835bef7b71ac1e03072ffa73f8 to your computer and use it in GitHub Desktop.
-module(rps).
-export([tournament/2]).
beat(rock) ->
paper;
beat(scissors) ->
rock;
beat(paper) ->
scissors.
lose(rock)->
scissors;
lose(scissors) ->
paper;
lose(paper) ->
rock.
result(Left,Right)->
BeatRight=beat(Right),
case Left == Right of
true -> 0;
false -> case BeatRight == Left of
true -> 1;
false -> -1
end
end.
% using the zip_with defined before
tournament(Xs,Ys) ->
Results = hofs:zip_with(fun result/2, Xs,Ys),
lists:sum(Results).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment