Let's say I have two kinds of items
data Item1 = A | B | C
data Item2 = D | E | F
And two sets
set1 = [A,B,C]
set2 = [D,E,F]
I would like to find all unique ways of matching the items from two sets, the answer should be (in informal notation):
AD,BE,CF
AD,BF,CE
AE,BD,CF
AE,BF,CD
AF,BD,CE
AF,BE,CD
In other words, I would like some function that accomplish the following:
combine :: [Item1] -> [Item2] -> [[(Item1,Item2)]]
combine = undefined
Note each combination should be a tuple, and each row in the enumeration scheme above should be a list, for example:
[(A,D),(B,E),(C,F)]
The formula to calculate the number of possible ways to combine these 2 sets is: 4 elevated 4^4. (for 2 equals sets it could be n^n, being n the size of the sets) And for n equals sets, the formula it should be: n^((n-1)*n) I hope it would help you.
To calculate combinations, we will use the formula nCr = n! / r! * (n - r)!, where n represents the total number of items, and r represents the number of items being chosen at a time.
Add a Custom Column to and name it List1. Enter the formula =List1. Expand out the new List1 column and then Close & Load the query to a table. The table will have all the combinations of items from both lists and we saved on making a custom column in List1 and avoided using a merge query altogether!
Use this
import Data.List (sort, permutations)
combine as bs = zipWith zip (repeat as) (sort $ permutations bs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With