Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Combinations class in Apache Commons Math

In [2]:
%classpath add mvn org.apache.commons commons-math3 3.6.1
In [3]:
import org.apache.commons.math3.util.Combinations
import scala.collection.JavaConverters._
Out[3]:
import org.apache.commons.math3.util.Combinations
import scala.collection.JavaConverters._
In [4]:
val it = new Combinations(6, 2).iterator()
it.foreach(System.out.println)
<console>:97: error: value foreach is not a member of java.util.Iterator[Array[Int]]
       it.foreach(System.out.println)
          ^
In [5]:
val it = new Combinations(5, 3).iterator()
while(it.hasNext()){
    System.out.print(it.next().mkString(" ") + "\n")
}
0 1 2
0 1 3
0 2 3
1 2 3
0 1 4
0 2 4
1 2 4
0 3 4
1 3 4
2 3 4
Out[5]:
null
In [ ]:

Comments