Skip to content

Instantly share code, notes, and snippets.

@ryanonsrc
Created January 6, 2016 04:02
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 ryanonsrc/abaeb34e583df1685e6c to your computer and use it in GitHub Desktop.
Save ryanonsrc/abaeb34e583df1685e6c to your computer and use it in GitHub Desktop.
object BinaryAddition {
def binaryAddition(a: Array[Int], b: Array[Int]): Array[Int] =
((Array.empty[Int] -> 0) /: (a zip b)) { case ((c, carry), (ai, bi)) =>
((sum:Int) => ((sum % 2) +: c) -> (sum / 2))(ai + bi + carry)
}._1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment