Skip to content

Instantly share code, notes, and snippets.

@nurugger07
Last active August 29, 2015 14:23
Show Gist options
  • Save nurugger07/a203770a04721859c1a3 to your computer and use it in GitHub Desktop.
Save nurugger07/a203770a04721859c1a3 to your computer and use it in GitHub Desktop.
defmodule BinaryGarden do
  def handshake(<< a :: size(16), "00", c :: binary-size(2) >>) when c == "AB" do
    "You testing me?"
  end
  def handshake(<< a :: size(16), b :: size(16), c :: size(16) >>), do: "Hello there!"
  def handshake(_), do: "Don't talk to strangers"
end
iex(1)> BinaryGarden.handshake("1200AB")
"You testing me?"
iex(1)> BinaryGarden.handshake("120034")
"Hello there!"
iex(2)> BinaryGarden.handshake("20034")
"Don't talk to strangers"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment