Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created July 6, 2013 23:56
Show Gist options
  • Save pragdave/5941709 to your computer and use it in GitHub Desktop.
Save pragdave/5941709 to your computer and use it in GitHub Desktop.
defrecord Poker.Card, face: 0, suit: "" do
def value(record) do
case record.face do
"A" -> 14
"K" -> 13
"Q" -> 12
"J" -> 11
"T" -> 10
int -> int
end
end
def from_string(<< value :: utf8, suit :: utf8 >>)
when suit in [?C, ?D, ?H, ?S] and ((value in ?2..?9) or (value in [?A, ?K, ?Q, ?J, ?T])) do
Poker.Card.new(face: <<value>>, suit: <<suit>>)
end
end
hand = "8C TS KC 9H 4S"
|> String.split
|> Enum.map(function(Poker.Card, :from_string, 1))
IO.inspect hand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment