import scala.collection.immutable._ // The nth element of the stream is a set containing n // elements, which represent vertices of a graph. val s = Stream.iterate(HashSet[AnyRef]()) { x => x + x } def r(t : HashSet[AnyRef]) : Boolean = { // All possible sets of red edges when the edges of the // graph are colored red or blue val p = t.subsets(2).toSet.subsets.toList // All sets of five vertices val c = t.subsets(5).map { _.subsets(2).toSet }.toList // Returns true if, for each graph with the given set of // vertices, there is a set of 5 vertices where all edges between them // are the same colors p.forall(x => { c.exists(y => { val i = x & y; i.size==0||i.size==10})}) } // Prints the Ramsey number R(5,5), which is known to be // between 43 and 49. The final python script produces the same // output regardless of which value between 43 and 49 it is fed. println(s.indexWhere(r))