Skip to content

Instantly share code, notes, and snippets.

@404pnf
Last active January 2, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 404pnf/8310660 to your computer and use it in GitHub Desktop.
Save 404pnf/8310660 to your computer and use it in GitHub Desktop.
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]] }
# <http://www.dzone.com/snippets/logic-gates-ruby>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment