Skip to content

Instantly share code, notes, and snippets.

@zkessin
Created May 6, 2019 11:18
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 zkessin/dedfe604af4ddd2bf7fb80e0d44b92dc to your computer and use it in GitHub Desktop.
Save zkessin/dedfe604af4ddd2bf7fb80e0d44b92dc to your computer and use it in GitHub Desktop.
defmodule ShuffleCards do
def suits() do
[:hearts, :spades, :clubs, :diamonds]
end
def cards do
[:ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king]
end
def shuffle() do
deck = for number <- cards(), suit <- suits(), do: {suit, number}
deck = for card <- deck, do: {:crypto.strong_rand_bytes(5), card}
deck = Enum.sort(deck)
deck = for {_, card} <- deck, do: card
{:ok, deck}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment