cartesian-product

Cartesian Product of Dictionary Keys and Values Python

假如想象 提交于 2019-12-11 03:18:48
问题 I have two lists with data: COURSES = [C1, C2, C3] ROOMS = [R1, R2, R3] and I already created a list of tuples containing their cartesian product: L_CR = list(itertools.product(COURSES, ROOMS)) #print(L_CR): [('C1', 'R1'), ('C1', 'R2'), ('C1', 'R3'), ('C2', 'R1')..... Now I have created two dictionaries storing integer values about the amount of people attending a course and the maximum amount of people fitting into a room: dic_courses = {'C1': 10, 'C2': 5, 'C3': 20} dic_rooms = {'R1': 5, 'R2

SQL query returning cartesian product

☆樱花仙子☆ 提交于 2019-12-10 18:15:11
问题 I have some tables: Employee: id, name, id_suc, id dep, id_sec Suc : id_suc, name Dep : id_dep, id_suc, name Sec : id_sec, id_dep, id_suc, name Don't blame on me, this is an existing application, I didn't create the Database and can't touch the structure since there is too much data inside and reports depending on it. I'm just trying to modify a report as asked. I do a query: SELECT DISTINCT s.name as sucurs, d.name as depart, c.name as section, e.name AS emp FROM employee e join suc s on (e

Duplicated results when performing INNER JOIN

可紊 提交于 2019-12-10 16:48:24
问题 I have 2 simple tables that I would like to perform an INNER JOIN with, but the problem is that I'm getting duplicated (for the columns str1 and str2) results: CREATE TABLE #A (Id INT, str1 nvarchar(50), str2 nvarchar(50)) insert into #A values (1, 'a', 'b') insert into #A values (2, 'a', 'b') CREATE TABLE #B (Id INT, str1 nvarchar(50), str2 nvarchar(50)) insert into #B values (7, 'a', 'b') insert into #B values (8, 'a', 'b') select * from #A a INNER JOIN #B b ON a.str1 = b.str1 AND a.str2 =

Prolog - Cartesian product calculator

隐身守侯 提交于 2019-12-10 15:28:42
问题 I need to create a Cartesian product calculator for Prolog. It should work like this: Input: product([1,2,3], [a,b], X). Output: X = [[1,a],[2,a],[3,a],[1,b],[2,b],[3,b]]. I know there are examples on the Internet, but I wanted to write something myself. This is my code and I think it's pretty close, but for some reason it doesn't exactly work. Any ideas, guys? % call new with 4 parameters (so we can keep List1 in memory) product(L1,L2,L3):- product(L1,L2,L3,L1). % stop when both List1 and

MYSQL: Avoiding cartesian product of repeating records when self-joining

一笑奈何 提交于 2019-12-10 09:31:58
问题 There are two tables: table A and table B. They have the same columns and the data is practically identical . They both have auto-incremented IDs, the only difference between the two is that they have different IDs for the same records. Among the columns, there is an IDENTIFIER column which is not unique , i.e. there are (very few) records with the same IDENTIFIER in both tables. Now, in order to find a correspondence between the IDs of table A and the IDs of table B, I have to join these two

Stream of cartesian product of other streams, each element as a List?

柔情痞子 提交于 2019-12-09 17:37:02
问题 How can I implement a function using Java 8 to take some number of streams, and produce a stream in which each element is a list consisting of one member of the Cartesian product of the streams? I've looked at this question -- that question uses an aggregator that is a BinaryOperator (taking two items of like type and producing an item of the same type). I'd like the items in the end result to be List s rather than the types of the elements in the input streams. Concretely, supposing my

Cartesian power (a special Cartesian product) — choose elements from array, in repeatable style

為{幸葍}努か 提交于 2019-12-08 07:09:02
问题 Input : There is an input array (assume there are no repeated elements) of length n . Output: And would like to print all possible array of the same length n consists of elements from input array, each input element could be used multiple times in the output array. Tips: n is variable among multiple inputs. For example Input array: [0, 1, 2] Expected output: 000 001 002 010 011 012 020 021 022 100 101 102 110 111 112 120 121 122 200 201 202 210 211 212 220 221 222 There are 3 * 3 * 3 = 27

Generating list of 2-lists in Scheme

此生再无相见时 提交于 2019-12-08 05:08:01
问题 (define cart-product (lambda (sos1 sos2) (if (null? sos1) '() (cons (cart-prod-sexpr (car sos1) sos2) (cart-product (cdr sos1) sos2))))) (define cart-prod-sexpr (lambda (s sos) (if (null? sos) '() (cons (list s (car sos)) (cart-prod-sexpr s (cdr sos)))))) Calling (cart-product '(q w) '(x y)) produces (((q x) (q y)) ((w x) (w y))) . How I can produce ((q x) (q y) (w x) (w y)) instead? 回答1: Untested. Note that the append-list procedure I defined actually returns a list ending in sos2 . That is

Creating Combinations of Elements

ぃ、小莉子 提交于 2019-12-08 02:52:22
I want to create product option system. I have a form look like this: Form's inputs are tag inputs. First input is option name. When you put any option name the new tag input added in the form. My problem: I can't create combinations in controller because the inputs name an quantity will be random. Current Code: I found this code but i cant customize it for my system First inputs code id: when i post data goes to controller post it another blade. i incude this in my page In controller public function sendd(Request $request){ $a = $request['data']; return view ('system.modules.variations',

Implement Ruby style Cartesian product in Go

吃可爱长大的小学妹 提交于 2019-12-07 17:47:19
问题 I want to get the Cartesian product of a , b , c , d : a = ['a1'] b = ['b1', 'b2'] c = ['c1', 'c2', 'c3'] d = ['d1'] Here is code in Ruby: e = [b, c, d] print a.product(*e) Output is: [ ["a1", "b1", "c1", "d1"], ["a1", "b1", "c2", "d1"], ["a1", "b1", "c3", "d1"], ["a1", "b2", "c1", "d1"], ["a1", "b2", "c2", "d1"], ["a1", "b2", "c3", "d1"] ] Is there a similar package or function that could do product in Golang? This is just simplified version, in fact, the input data is like [['a1'], ['b1',