cartesian-product

Scala - can yield be used multiple times with a for loop?

◇◆丶佛笑我妖孽 提交于 2019-12-17 19:37:31
问题 An example: val l = List(1,2,3) val t = List(-1,-2,-3) Can I do something like this? for (i <- 0 to 10) yield (l(i)) yield (t(i)) Basically I want to yield multiple results for every iteration. 回答1: It's not clear what you're asking for - what you expect the semantics of multiple yield to be. One thing, though, is that you probably never want to use indexes to navigate a list - each call to t(i) is O(i) to execute. So here's one possibility that you might be asking for scala> val l = List(1,2

Cartesian product of objects in javascript

天大地大妈咪最大 提交于 2019-12-17 18:59:12
问题 I need to generate a complete set of variants based on a list of N attributes, while keeping the attribute name intact. var input = [ { 'colour' : ['red', 'green'] }, { 'material' : ['cotton', 'wool', 'silk'] }, { 'shape' : ['round', 'square', 'rectangle'] } ]; var expected = [ { 'colour': 'red', 'material': 'cotton', 'shape': 'round' }, { 'colour': 'red', 'material': 'cotton', 'shape': 'square' }, { 'colour': 'red', 'material': 'cotton', 'shape': 'rectangle' }, { 'colour': 'red', 'material':

Scala method to combine each element of an iterable with each element of another?

妖精的绣舞 提交于 2019-12-17 16:36:08
问题 If I have this: val a = Array("a ","b ","c ") val b = Array("x","y") I would like to know if such a method exists which would let me traverse the first collection, and for each of it's elements, walk the entire second collection. For example, if we take the array a , we would have a,x , a,y , b,x , b,y , c,x , c,y . I know of zip but from what I've seen it only works on collections of the same sizes, and it associates elements from same positions. 回答1: I'm not sure of a "method", but this can

How do I compute the cartesian product of n sequences in F#?

一个人想着一个人 提交于 2019-12-17 16:28:23
问题 I was given a puzzle as a present. It consists of 4 cubes, arranged side by side. The faces of each cube are one of four colours. To solve the puzzle, the cubes must be orientated so that all four cubes' tops are different, all their fronts are different, all their backs are different and all their bottom's are different. The left and right sides do not matter. My pseudo-code solution was: Create a representation of each cube. Get all the possible orientations of each cube (there are 24 for

Cartesian product of streams in Java 8 as stream (using streams only)

和自甴很熟 提交于 2019-12-17 07:37:53
问题 I would like to create a method which creates a stream of elements which are cartesian products of multiple given streams (aggregated to the same type at the end by a binary operator). Please note that both arguments and results are streams, not collections. For example, for two streams of {A, B} and {X, Y} I would like it produce stream of values {AX, AY, BX, BY} (simple concatenation is used for aggregating the strings). So far, I have came up with this code: private static <T> Stream<T>

How to get Cartesian product from different group member? [duplicate]

旧街凉风 提交于 2019-12-14 00:06:13
问题 This question already has an answer here : print out all combinations of index (1 answer) Closed 2 years ago . As the title mentioned, I have some problems in C++. If I have a std::vector<std::vector<int> >tmpvec vector < vector <int> > tmpvec = { {1,2,3}, {4,5}, {6,7,8,9}, {10,11} }; how can I generate all possible combination of a vector of vector 1,4,6,10 1,4,6,11 1,4,7,10 1,4,7,11 ...... There are at most 48 different combination. 回答1: You may do bool increase(const std::vector<std:

SQL Server query returning many cartesian product

只愿长相守 提交于 2019-12-13 23:18:12
问题 I have a SQL Server query which looks like this: select ISNULL(UPPER(w.role), '-') as 'Position Title', concat ('SGD ',m.expectedSalary) as 'Expected Salary', (cast(w.endYear as int) - cast(w.startYear as int)) as 'Experience', mq.Qualification as 'Education Level', ISNULL(ms.specialisation, '-') as 'Specialisation', mj.dateApplied as 'Date of Application' from WorkExpr w, Member m, MemberQlftn mq, MemberSpln ms, MemberJob mj where mj.jobNumber = (select jobNumber from MemberJob where email =

Java Guava CartesianProduct

老子叫甜甜 提交于 2019-12-13 06:24:47
问题 I am exploring Java Guava Library by writing small snippets of code. Here is what I wrote for finding the cartesian product of n-sets. Documentation here //allLists populated above ... List<Set> interimList = new ArrayList<Set>(); for(List<String> tmp : allLists) //converting List<List> to List<Set> { Set interimSet = new HashSet(tmp); interimList.add(interimSet); } System.out.println(interimList); Sets.cartesianProduct(interimList); But this is not compiling. The last line Sets

Cartesian Product for two dictionaries python

十年热恋 提交于 2019-12-13 06:06:38
问题 ok so i've got two dictionaries. dictionary_1 = {'status': ['online', 'Away', 'Offline'], 'Absent':['yes', 'no', 'half day']} dictionary_2 = {'healthy': ['yes', 'no'], 'insane': ['yes', 'no'] Now i need to combine them so that i get a new dictionary with: {'status': ['online', 'online', 'away', 'away', 'Offline', 'Offline'], 'Absent': ['yes', 'yes', 'no', 'no', 'half day', 'half day'], 'healthy': ['yes', 'no', 'yes', 'no', 'yes', 'no'], 'insane': ['yes', 'no', 'yes', 'no', 'yes', 'no'] } This

How can I create cartesian product of vector of vectors?

吃可爱长大的小学妹 提交于 2019-12-13 02:47:44
问题 I've a vector of vectors say vector<vector<int> > items of different sizes like as follows 1,2,3 4,5 6,7,8 I want to create combinations in terms of Cartesian product of these vectors like 1,4,6 1,4,7 1,4,8 and so on till 3,5,8 How can I do that ? I've looked up several links and I've also listed them at the end of this post but I'm not able to interpret that as I'm not that familiar with the language. Could some body help me with this. #include <iostream> #include <iomanip> #include <vector>