fork download
  1. object Main extends App {
  2. case class State(a: Int, b: Int, sum:Int, prod:Int)
  3.  
  4. val allPossibleStates:Seq[State] = for {
  5. i <- 1 to 99;
  6. j <- i to 99
  7. } yield State(i,j,i+j,i*j)
  8.  
  9. (1 to 7).foldLeft(allPossibleStates)( (states, _) =>
  10. states
  11. .groupBy(_.prod).filter(_._2.size > 1).flatMap(_._2)
  12. .groupBy(_.sum).filter(_._2.size > 1).flatMap(_._2)
  13. .toSeq
  14. ).groupBy(_.prod).filter(_._2.size == 1).flatMap(_._2)
  15. .map(println)
  16. }
Success #stdin #stdout 0.63s 322176KB
stdin
Standard input is empty
stdout
State(77,84,161,6468)