Last active
February 22, 2017 15:05
-
-
Save sortega/086e99dc77f067e063834e407e9a668f to your computer and use it in GitHub Desktop.
Solve the 3 daughters problem in a few Scala lines
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
val options = (for { | |
a <- 1 to 36 | |
b <- 1 to 36 | |
c <- 1 to 36 | |
if a*b*c == 36 | |
} yield Vector(a, b, c).sorted).distinct | |
val groups = options.groupBy(_.sum) | |
val ambiguousOptions = groups.values.find(_.size > 1).get | |
val solution = ambiguousOptions.find { case Vector(a, b, c) => | |
c > a && c > b | |
}.get | |
println(solution.mkString(", ")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment