Created
January 8, 2019 06:20
-
-
Save mlhaufe/03730b09c1d50255f123140d2cde6f7e to your computer and use it in GitHub Desktop.
Booleans with arithmetic
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
// x, y :: {0,1} | |
var and = (x,y) => x * y, | |
not = (x) => 1 - x, | |
or = (x,y) => 1 - (1 - x) * (1 - y) | |
and(0,0) // 0 | |
and(0,1) // 0 | |
and(1,0) // 0 | |
and(1,1) // 1 | |
not(0) // 1 | |
not(1) // 0 | |
or(0,0) // 0 | |
or(0,1) // 1 | |
or(1,0) // 1 | |
or(1,1) // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment