Skip to content

Instantly share code, notes, and snippets.

@einblicker
Created January 31, 2012 17:20
Show Gist options
  • Save einblicker/1711689 to your computer and use it in GitHub Desktop.
Save einblicker/1711689 to your computer and use it in GitHub Desktop.
object ParityBit {
type B = Int
def f(x1: B, x2: B, x3: B, x4: B) =
(x1 ^ x2 ^ x3,
x1 ^ x2 ^ x4,
x2 ^ x3 ^ x4)
def g(x1: B, x2: B, x3: B, x4: B)(
c1:B, c2:B, c3:B
) =
(x1 ^ x2 ^ x3 ^ c1,
x1 ^ x2 ^ x4 ^ c2,
x2 ^ x3 ^ x4 ^ c3)
def problem1 = {
println(f(1,0,1,0)) // 0 1 1
println(f(0,1,1,0)) // 0 1 0
println(f(1,1,0,1)) // 0 1 0
}
def problem2 = {
println(g(0, 1, 0, 0)(0, 0, 0)) // 1 1 1
println(g(0, 0, 0, 1)(0, 0, 0)) // 0 1 1
println(g(0, 0, 0, 0)(0, 1, 0)) // 0 1 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment