Created
December 11, 2015 22:54
-
-
Save mmrobins/df54ebe7cf28f58c2a00 to your computer and use it in GitHub Desktop.
Elixir Rock Paper Scissors
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
import String | |
import Enum | |
l= ~w{r p s} | |
m=IO.gets "" | |
n=m|>strip|>split("",trim: true) | |
if any?(n,fn(x)->!member?(l,x)end)do | |
else | |
f = fn()->random l end | |
o = [f.(), f.(), f.()] | |
IO.puts o | |
g=fn(x)->case x do | |
{x,x}->0 | |
{"r","s"}->1 | |
{"p","r"}->1 | |
{"s","p"}->1 | |
_->-1 | |
end | |
end | |
case zip(n,o)|>map(g)|>sum do | |
0->"Draw" | |
x when x > 0->"Win" | |
_->"Lose" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment