Last active
December 11, 2015 23:45
-
-
Save markolson/420d59d8a6f665254a5e to your computer and use it in GitHub Desktop.
Elixir Rock Paper Scissors Golf
This file contains hidden or 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 Enum | |
t = 'rps' | |
c = fn(s)-> into(s,HashSet.new) end | |
s = (IO.gets'') |> String.strip |> String.to_char_list | |
case count(Set.difference(c.(s),c.(t))) do | |
0 when length(s)==3-> -> | |
e = for x<-s, do: {x,random(t)} | |
x = sum(map(e,fn(x) -> case x do {x,x}->0;{?r,?s}->1;{?p,?r}->1;{?s,?p}->1;_->-1 end end)) | |
IO.puts map(e,&(elem(&1,1))) | |
IO.puts(x<0&&"Lose"||x>0&&"Win"||"Draw") | |
_ -> | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment