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)) =>
((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