Anton Shestakov <engored@ya.ru>, Wed, 26 Feb 2014 19:05:32 +0900
rps5 rules.
rps3.erl
Permissions: -rw-r--r--
-export([get_rules/0, beats/1, test_beats/0, test_loses/0, winning_hand/1, test_winning_hand/0]). get_rules() -> [rock, paper, scissors]. beats(H, lists:reverse(get_rules())). io:format("~w beats ~w.~n", [H, beats(H)]) io:format("~w loses to ~w.~n", [H, loses(H)]) % rock, rock, rock -> rock % rock, paper, scissors -> undefined % rock, paper, paper -> paper % rock, rock, paper -> paper HSet = sets:from_list(Hands), case sets:is_element(loses(Hand), HSet) of Winner = winning_hand(Hands), io:format("~w wins in ~w.~n", [Winner, Hands])