Skip to content

Instantly share code, notes, and snippets.

@markolson
Last active December 11, 2015 23:45
Show Gist options
  • Save markolson/420d59d8a6f665254a5e to your computer and use it in GitHub Desktop.
Save markolson/420d59d8a6f665254a5e to your computer and use it in GitHub Desktop.
Elixir Rock Paper Scissors Golf
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