Home › Forums › kdb+ › Cartesian Products › Re: Cartesian Products
-
Hi jn001,
Welcome to the KX Community
How are you currently generating your permutations?
q)x:2 q)n:8 q)fac:{prd 1+til x} q)p:`long$fac[n] xexp x; / max permutations q)s:1+til p; / list of n permutations
I.e. determining the actual number of permutations is easy in q
q)fac[8] xexp 8 6.9849642471415143e+036
However for each factor added, the list you will be creating will use a lot more ram so you could hit ‘wsfull depending on your machine size.
In that case you might want to split up the calculations and iteratively calculate each before joining the results together (a kind of ‘map-reduce’ if you will.)
Notes:
- ‘fac’ taken from the phrases.
- cross may also be of interest to you, for example creating the list of players and games they can participate in:
q)x:2 q)n:4 q)flip `players`games!flip (1+til n) cross (1+til x) players games ------------- 1 1 1 2 2 1 2 2 3 1 3 2 4 1 4 2
I hope this helps provoke some ideas and to kick of this thread
David