Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
object BinaryAddition {
def binaryAddition(a: Array[Int], b: Array[Int]): Array[Int] =
((Array.empty[Int] -> 0) /: (a zip b)) { case ((c, carry), (ai, bi)) =>
(((ai + bi + carry) % 2) +: c) -> (ai + bi + carry) / 2
}._1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment