Last active
August 29, 2015 14:06
-
-
Save FluffyCode/34cf42bad2d9370da2a3 to your computer and use it in GitHub Desktop.
Logic Gates in Ruby
This file contains hidden or 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
# logic gates, via | |
# http://www.dzone.com/snippets/logic-gates-ruby | |
NAND = lambda { |i, j| !(i && j) } | |
NOT = lambda { |i| NAND[i, i] } | |
AND = lambda { |i, j| NOT[NAND[i, j]] } | |
OR = lambda { |i, j| NAND[NAND[i, i], NAND[j, j]] } | |
NOR = lambda { |i, j| NOT[OR[i, j]] } | |
XOR = lambda { |i, j| NAND[NAND[i, NAND[i, j]], NAND[j, NAND[i, j]]] } | |
XNOR = lambda { |i, j| NOT[XOR[i, j]] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment