Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Last active August 29, 2015 14:04
Show Gist options
  • Save jackliusr/b2962b776d586f6eda3e to your computer and use it in GitHub Desktop.
Save jackliusr/b2962b776d586f6eda3e to your computer and use it in GitHub Desktop.
Resolve Gem Stones in functional programming way
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