Skip to content

Instantly share code, notes, and snippets.

@sortega
Last active February 22, 2017 15:05
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 sortega/086e99dc77f067e063834e407e9a668f to your computer and use it in GitHub Desktop.
Save sortega/086e99dc77f067e063834e407e9a668f to your computer and use it in GitHub Desktop.
Solve the 3 daughters problem in a few Scala lines
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