Skip to content

Instantly share code, notes, and snippets.

@davepkennedy
Created June 25, 2014 20:25
Show Gist options
  • Save davepkennedy/dfd923cd2f03df1016fa to your computer and use it in GitHub Desktop.
Save davepkennedy/dfd923cd2f03df1016fa to your computer and use it in GitHub Desktop.
Adding two numbers without using +
def add (a: Int, b: Int): Int = {
@tailrec
def helper (c: Int, d: Int): Int = d match {
case 0 => c
case _ => helper (c ^ d, (c & d) << 1)
}
helper(a, b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment