RosettaCodeData/Task/Ternary-logic/Groovy/ternary-logic-1.groovy
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

18 lines
589 B
Groovy

enum Trit {
TRUE, MAYBE, FALSE
private Trit nand(Trit that) {
switch ([this,that]) {
case { FALSE in it }: return TRUE
case { MAYBE in it }: return MAYBE
default : return FALSE
}
}
private Trit nor(Trit that) { this.or(that).not() }
Trit and(Trit that) { this.nand(that).not() }
Trit or(Trit that) { this.not().nand(that.not()) }
Trit not() { this.nand(this) }
Trit imply(Trit that) { this.nand(that.not()) }
Trit equiv(Trit that) { this.and(that).or(this.nor(that)) }
}