Skip to content

Instantly share code, notes, and snippets.

@mmrobins
Created December 11, 2015 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmrobins/df54ebe7cf28f58c2a00 to your computer and use it in GitHub Desktop.
Save mmrobins/df54ebe7cf28f58c2a00 to your computer and use it in GitHub Desktop.
Elixir Rock Paper Scissors
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