Match3 implementation in Scala