Last active
August 29, 2015 14:04
-
-
Save jackliusr/b2962b776d586f6eda3e to your computer and use it in GitHub Desktop.
Resolve Gem Stones in functional programming way
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
object Solution { | |
def intersect(a: Set[Char], b: Set[Char]) = a & b | |
def main(args: Array[String]) { | |
val lines =io.Source.stdin.getLines().toList | |
val cases = lines.drop(1) | |
val caseSets = cases.map(c => c.distinct).map(c => c.toSet) | |
val resultSet = caseSets.reduce(intersect) | |
println(resultSet.size) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment