Created
February 24, 2017 11:47
-
-
Save waynejo/a4ebf11f379635012c31e7ce7f07afcb 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 Main { | |
def AND(x1:Double, x2:Double): Double = { | |
val w1 = 0.5 | |
val w2 = 0.5 | |
val b = -0.7 | |
val tmp = x1 * w1 + x2 * w2 + b | |
if (tmp <= 0) { | |
0 | |
} else { | |
1 | |
} | |
} | |
def NAND(x1:Double, x2:Double): Double = { | |
val w1 = -0.5 | |
val w2 = -0.5 | |
val b = 0.7 | |
val tmp = x1 * w1 + x2 * w2 + b | |
if (tmp <= 0) { | |
0 | |
} else { | |
1 | |
} | |
} | |
def OR(x1:Double, x2:Double): Double = { | |
val w1 = 0.5 | |
val w2 = 0.5 | |
val b = -0.3 | |
val tmp = x1 * w1 + x2 * w2 + b | |
if (tmp <= 0) { | |
0 | |
} else { | |
1 | |
} | |
} | |
def XOR(x1:Double, x2:Double): Double = { | |
val s1 = NAND(x1, x2) | |
val s2 = OR(x1, x2) | |
AND(s1, s2) | |
} | |
def main(args:Array[String]) { | |
println(XOR(0, 0)) | |
println(XOR(1, 0)) | |
println(XOR(0, 1)) | |
println(XOR(1, 1)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment