I need to generate the combinations for a list of 30,000 items using scalas combinations method on a stream / list
1 to 30000.toStream.combinations(2).size
This function never completes. When I try the same operation in python
r = list(range(1,30000))
z = itertools.combinations(r, 2)
%time sum(1 for _ in z)
The operation completes in 26.2 seconds.
Whats going on here? How can I generate the combinations of a very large list in scala?
combination
method specifies that only one occurrence for each combination should be given. SoList(1, 2, 2).combinations(2).toList.ordered == List(List(1, 2), List(2, 1))
. I don't know whether OP is interested in this property or not, but it will certainly take some time longer to rundistinct
on your output (although probably still much less time than stdlib's implementation). – Bulky