Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created April 26, 2015 08:59
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 shigemk2/c0e3180a6e6c9487808b to your computer and use it in GitHub Desktop.
Save shigemk2/c0e3180a6e6c9487808b to your computer and use it in GitHub Desktop.
object Color extends Enumeration {
val Blue, Red, Magenta, Green, Cyan, Yellow, White = Value
}
object Main {
import Color._
def mix(a:Color.Value, b:Color.Value): Color.Value = {
(a, b) match {
case (Blue, Red) => Magenta
case (Blue, Magenta) => Magenta
case (Blue, Green) => Cyan
case (Blue, Cyan) => Cyan
case (Blue, Yellow) => White
case (Red, Magenta) => Magenta
case (Red, Green) => Yellow
case (Red, Cyan) => White
case (Red, Yellow) => Yellow
case (Magenta, Green) => White
case (Magenta, Cyan) => White
case (Magenta, Yellow) => White
case (Green, Cyan) => Cyan
case (Green, Yellow) => Yellow
case (Cyan, Yellow) => White
case (White, _) => White
case (a, b) if a == b => a
case (a, b) => mix(b, a)
}
}
def main(args: Array[String]): Unit = {
println(mix(Red, Red))
println(mix(Red, Blue))
println(mix(Blue, mix(Blue, Green)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment