Permutation Combinations Mobile Pattern Codes [closed]

Please help write codes to determine 4 to 6 dot patterns. I am stuck after permutations input. It would really help if one could write direct so I could copy paste code to determine list of 4 to 6 dot patterns. Pl refer article.

https://www.guokr.com/article/49408/ I have uploaded jpeg of the error I am facing Code error at =Flatten[{#, Reverse@#} & /@ Partition[{1, 3, 4, 6, 7, 9, 1, 7, 2, 8, 3, 9, 1, 9, 3, 7}, 2], 1]

PostgreSQL efficient lookup for 2 column combinations

I have a PostgreSQL (v. 12) database storing match results. I have integer columns team_home and team_away which have foreign key constraints for team_id in table teams . My question has a few scenarios:

  1. If I want to find all games involving a single team with ID 1 I could do:

SELECT * FROM matches WHERE team_home = 1 OR team_away = 1;

  1. If I wanted to find all games between 2 teams, IDs 1 and 2 I could do:

SELECT * FROM matches WHERE (team_home = 1 AND team_away = 2) OR (team_home = 2 AND team_away = 1);

  1. I want to join my matches table with a teams table:

.

SELECT m.match_id, t1.name, t2.name  FROM matches m  JOIN teams t1 ON t1.team_id = m.team_home  JOIN teams t2 ON t2.team_id = m.team_away  WHERE m.team_home = 1 OR m.team_away = 1; 

The question I have is – are these the optimal queries and can I improve efficiency?

I have read a bit about indexes and this page seems to suggest I could improve my queries across two columns like this by using a GIN index, however that is for text columns and not Foreign Key integer columns.

Alternatively should I create an ARRAY column of team ids and then use an ANY query? (The obvious downside to that is you lose the abilit

Generate all combinations for variables and insert into temp table

0

I have one requirement there are 4 variables and i want all combinations of 4 variables and insert into temp table .

DECLARE StartDateTime DATETIME; DECLARE Age INT;  DECLARE Duration INT ; DECLARE TotalDD INT;  CREATE TEMPORARY TABLE tempTable(     Duration INT,     TotalDD INT,     Age INT,     StartDateTime DATETIME,     ); SET Age = 16; SET TotalDD = 14; SET Duration = 30; SET StartDateTime = CURDATE(); 

Excepted Result:

Duration age TotalDD StartDateTime 30 null null null null 16 null null 30 null null null 30 16 null null null null 14 20200622 30 null 14 null 30 16 null 20200622 

……….. ………. so on

How to get started with multi-level pairwise combinations

Let’s say we have 4 ranks: 1-4

Every rank has a set of unique nodes, each pair of same-rank nodes can be combined to create a node of a rank 1 level higher, in any number of combinations:

1-A + 1-B = 2-C 1-A + 1-A = 2-B 1-A + 1-C = 2-C 1-B + 1-C = 2-A 

These combinations are deterministic, we have a lookup table to get any pair-result combination and the result is not unique.

Once combined, they cannot be used again. So in the example above, we can do:

We have [1-A, 1-A, 1-B, 1-C] We perform 1-A + 1-A = 2-B Now the only nodes we have left are 1-B and 1-C = 2-A 

Rank 4’s cannot combine, they are the final rank.

Let’s say I have a random set of Rank 1, 2, and 3 nodes.

I would like to build a “planner” where the user can see paths to Rank 4 and decide which nodes to use.

I have a simple algorithm where I calculate all combinations of each rank, get the results and pass it up to the next rank to perform the same algorithm:

1. starting set = [1-A, 1-A, 1-B, 1-C, 2-A] 2. split into buckets: [1-A, 1-A, 1-B, 1-C] and [2-A] 3. go through Rank 1, create all combinations: C(4,2) = 6 4. add the resulting 6 to the single node of Rank 2 for a total of n = 7 5. repeat step 3-4 for Rank 2: C(n,r) = 21 6. repeat step 3-4 for Rank 3: C(n,r) = 210 

The problem here is that with a small set of 5 starting nodes, the possibilities exponentially grow and with 210 possible Rank 4 paths, will get very noisy.

Since any two nodes can only be used once, with a starting set of length 5, if I choose a random 2 to merge, this will remove pretty much all the later paths.

How do I somehow reduce the noise? I’m not sure if I should be looking at Graph Theory, some other simple algorithm, or do a grouping/counting of unique nodes.

Algorithm to generate combinations of n elements from n sets of m elements

Suppose I have 3 sets of 2 elements: [A, B], [C, D], [E, F], and I wanted to generate all possible combinations of 1 element from each set, such that the result of the algorithm would be:

[A, C, E], [A, C, F], [A, D, E], [A, D, F], [B, C, E], [B, C, F], [B, D, E], [B, D, F] 

What algorithm can I use to generate all combinations. Keep in mind that I’m looking for an algorithm that will work on any number of sets that have any number of elements, the above is just an example. Also, remember that I’m looking for an algorithm to actually generate the combinations, not just count them.

What is the running time of generating all $k$ combinations of $n$ items $\binom{n}{k}$?

I was solving the following problem, just for reference (441 – Lotto). It basically requires the generation all $ k$ -combinations of $ n$ items

void backtrack(std::vector<int>& a,                int index,                std::vector<bool>& sel,                int selections) {     if (selections == 6) { // k is always 6 for 441 - lotto         //print combination         return;     }     if (index >= a.size()) { return; } // no more elements to choose from     // two choices     // (1) select a[index]     sel[index] = true;     backtrack(a, index+1, sel, selections+1);      // (2) don't select a[index]     sel[index] = false;     backtrack(a, index+1, sel, selections);  } 

I wanted to analyze my own code. I know at the top level (level = 0), I’m making one call. At the next level (level=1) of recursion, I have two calls to backtrack. At the following level, I have $ 2^2$ calls. The last level would have $ 2^n$ subproblems. For each call, we make $ O(1)$ work of selecting or not selecting the element. So the total time would be $ 1+2+2^2+2^3+…+2^n = 2^{n+1} – 1 = O(2^{n})$

I was thinking since we’re generating $ \binom{n}{k}$ combinations that there might be a better algorithm with a better running time since $ \binom{n}{k}=O(n^2)$ or maybe my algorithm is wasteful and there is a better way? or my analysis in fact is not correct? Which one is it?

Generate only unique combinations when input contains duplicates

I have a list with repeated elements, such as

list = {a, a, b, c, c, c}

and I’d like a list of the unique ways to choose 3 elements from it:

{{a, a, b}, {a, a, c}, {a, b, c}, {a, c, c}, {b, c, c}, {c, c, c}} 

Alas, “unique” means two different things at once in that sentence, and I can’t figure out how to achieve both types of uniqueness simultaneously.

I could use Permutations, whose documentation indicates regarding the input that

Repeated elements are treated as identical.

But I will have many results that differ only by rearrangement, and I do not care about order:

Permutations[list, {3}]

{{a, a, b}, {a, a, c}, {a, b, a}, {a, b, c}, {a, c, a}, {a, c, b}, {a, c, c}, {b, a, a}, {b, a, c}, {b, c, a}, {b, c, c}, {c, a, a}, {c, a, b}, {c, a, c}, {c, b, a}, {c, b, c}, {c, c, a}, {c, c, b}, {c, c, c}} 

To eliminate the rearrangements, I could try using Subsets instead, but per its documentation,

Different occurrences of the same element are treated as distinct.

As a result I get many duplicate results that I don’t want due to the repeated elements of list:

Subsets[list, {3}]

{{a, a, b}, {a, a, c}, {a, a, c}, {a, a, c}, {a, b, c}, {a, b, c}, {a, b, c}, {a, c, c}, {a, c, c}, {a, c, c}, {a, b, c}, {a, b, c}, {a, b, c}, {a, c, c}, {a, c, c}, {a, c, c}, {b, c, c}, {b, c, c}, {b, c, c}, {c, c, c}} 

[Frustrated aside: I can’t begin to imagine why Mathematica’s permutations-generating function treats repeated list items differently than its combinations-generating function.]

I could eliminate the duplicates from either result, but either way, that still requires calculating the full list of nonunique results as an intermediate step, which I expect to be many orders of magnitude longer than the unique results.

Is it possible to get the result I’m after without having to cull a humongously longer list first to get there?

Restrict crawling of region/lang combinations other than the provided ones in robots.txt

I want to allow crawling of my website only if the URL starts with accepted region/language combinations which are us/en, gb/en and fr/fr. Other language combinations must be restricted. On the other hand crawler should be able to crawl / or /about, etc. For example:

example.com/us/en/videos  # should be allowed example.com/de/en/videos  # should be blocked example.com/users/mark    # should be allowed 

Again, it should be blocked only if it starts with unaccepted region/language combinations. What I did so far does not work:

Disallow: /*? Disallow: /*/*/cart/ Disallow: /*/*/checkout/ Disallow: /*/*/ Allow: /*.css? Allow: /*.js? Allow: /us/en/ Allow: /gb/en/ Allow: /fr/fr/ 

I tested it with google’s online robots.txt tester.

Time complexity of combinations of n pairs of parentheses

I have the following code snippet for combinations of n pairs of parentheses.

def parens(n):     if n <= 0:         return ['']     else:         combinations = []         helper('', n, n, combinations)         return combinations   def helper(string, left, right, combinations):     if left <= 0 and right <= 0:         combinations.append(string)     else:         if left > 0:             helper(string + '(', left - 1, right, combinations)         if right > left and right > 0:             helper(string + ')', left, right - 1, combinations) 

What’s the reasonable estimation of the time complexity of it?

My trial:

  1. (2n)!/n!n! since it’s full permutation with the same elelment with more limitation:(upper bound)
  2. Resolve recurrence: T(n) = 2T(n-1) => O(2^n)

What overpowered combinations would be available if I allow a bonus action to be used in place of a standard action?

It has come up in game a couple of times that a player might want to cast a spell that has a casting time of 1 bonus action using their “main” action (if they have another bonus action they also want to take on that turn, such as giving bardic inspiration, or controlling a Bigby’s hand, etc.)

On the face of it, it seems obvious that something (a bonus action) that is usually much faster than a full action could be done as your full action. Although the question comes up most often with respect to spellcasting, if I house rule this, I would rule that any bonus action can be taken as a regular action instead; however, I would not allow the same type of bonus action to be taken twice (so no giving bardic inspiration to two allies on the same turn, for instance).

Are there any abusive or overpowered combinations I should be wary of if I were to allow a character to take 2 bonus actions instead of one regular action and one bonus action on a turn?

The issue of casting two bonus-action spells would not come up because the rule against casting 2 spells on your turn unless one of them is a cantrip with a casting time of 1 action would still be in effect:

PHB p. 203 (under Bonus Action casting time)

You can’t cast another spell during the same turn, except for a cantrip with a casting time of 1 action.

I know it’s hard to prove/justify a negative answer to a question like this, but I’d be happy to get answers that say you don’t think there would be any issues if you describe how you came to that conclusion.