fork download
  1. enum Direction {
  2. North, South, East, West, Up, Down
  3. Direction getOpposite() {
  4. values()[ordinal() + ordinal() % 2 * -2 + 1]
  5. }
  6. }
  7.  
  8. Direction.values().each {
  9. println "opposite of $it is $it.opposite"
  10. }
  11.  
Success #stdin #stdout 1.17s 217600KB
stdin
Standard input is empty
stdout
opposite of North is South
opposite of South is North
opposite of East is West
opposite of West is East
opposite of Up is Down
opposite of Down is Up