Created
January 6, 2016 04:02
-
-
Save ryanonsrc/abaeb34e583df1685e6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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