combinations

Permutations with repetition without two consecutive equal elements

浪子不回头ぞ 提交于 2020-04-13 15:37:46
问题 I need a function that generates all the permutation with repetition of an iterable with the clause that two consecutive elements must be different; for example f([0,1],3).sort()==[(0,1,0),(1,0,1)] #or f([0,1],3).sort()==[[0,1,0],[1,0,1]] #I don't need the elements in the list to be sorted. #the elements of the return can be tuples or lists, it doesn't change anything Unfortunatly itertools.permutation doesn't work for what I need (each element in the iterable is present once or no times in

Python combine items in a dictionary

走远了吗. 提交于 2020-03-25 04:05:03
问题 Suppose I have A dictionary A A={'a':{0:[1,2,3],1:[4,5,6]},'b':{0:['u','v','w'],1:['x','y','z']}} I want to combine all the elements in 'a' and 'b' that [[1,2,3,'u','v','w'], [1,2,3,'x','y','z'], [4,5,6,'u','v','w'], [4,5,6,'x','y','z']] I have tried: c=[] for k,v in A.items(): for i,t in v.items(): c.append(t+t) But it does not give the desired result. 回答1: As an alternative to the itertools method outlined above by Ajax1234, you can do it with just list comprehensions: Start with

Python combine items in a dictionary

别来无恙 提交于 2020-03-25 04:03:49
问题 Suppose I have A dictionary A A={'a':{0:[1,2,3],1:[4,5,6]},'b':{0:['u','v','w'],1:['x','y','z']}} I want to combine all the elements in 'a' and 'b' that [[1,2,3,'u','v','w'], [1,2,3,'x','y','z'], [4,5,6,'u','v','w'], [4,5,6,'x','y','z']] I have tried: c=[] for k,v in A.items(): for i,t in v.items(): c.append(t+t) But it does not give the desired result. 回答1: As an alternative to the itertools method outlined above by Ajax1234, you can do it with just list comprehensions: Start with

R : How to have combinations that match requirements [closed]

偶尔善良 提交于 2020-03-16 10:00:43
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 days ago . I have a dataframe with courses ("courses") and the number of hours the course is teached for a year ("hours") my problem is that for each course, i have to choose someone to teach it. every teacher have a profil which are either : "Perm", "Vac", "temp", "other" The amount of hours teach a year (the

Brute force attack test on password for file

你离开我真会死。 提交于 2020-03-05 11:46:06
问题 I'm trying to create a brute force that will work on a specific files password. I'm not sure how to get this code to work. This is what I have so far. This code produces the correct possible combinations for the password but I am not sure how to implement this into a brute force attack. my @alpha = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z); my $password = @alpha[1]; my @combo = (); for my $one(@alpha){ for my $two(@alpha){ for my $three(@alpha){ for my $four(@alpha){ push @combo

Brute force attack test on password for file

浪子不回头ぞ 提交于 2020-03-05 11:46:05
问题 I'm trying to create a brute force that will work on a specific files password. I'm not sure how to get this code to work. This is what I have so far. This code produces the correct possible combinations for the password but I am not sure how to implement this into a brute force attack. my @alpha = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z); my $password = @alpha[1]; my @combo = (); for my $one(@alpha){ for my $two(@alpha){ for my $three(@alpha){ for my $four(@alpha){ push @combo

Best way to combine a permutation of conditional statements

纵饮孤独 提交于 2020-02-28 04:25:18
问题 So, I have a series of actions to perform, based on 4 conditional variables - lets say x,y,z & t. Each of these variables have a possible True or False value. So, that is a total of 16 possible permutations. And I need to perform a different action for each permutation. What is the best way to do this rather than making a huge if-else construct. Lets see a simplified example. This is how my code would look if I try to contain all the different permutations into a large if-else construct. if

Best way to combine a permutation of conditional statements

独自空忆成欢 提交于 2020-02-28 04:22:33
问题 So, I have a series of actions to perform, based on 4 conditional variables - lets say x,y,z & t. Each of these variables have a possible True or False value. So, that is a total of 16 possible permutations. And I need to perform a different action for each permutation. What is the best way to do this rather than making a huge if-else construct. Lets see a simplified example. This is how my code would look if I try to contain all the different permutations into a large if-else construct. if

Best way to combine a permutation of conditional statements

谁都会走 提交于 2020-02-28 04:20:35
问题 So, I have a series of actions to perform, based on 4 conditional variables - lets say x,y,z & t. Each of these variables have a possible True or False value. So, that is a total of 16 possible permutations. And I need to perform a different action for each permutation. What is the best way to do this rather than making a huge if-else construct. Lets see a simplified example. This is how my code would look if I try to contain all the different permutations into a large if-else construct. if

Get all combinations for arbitrary number of elements

痞子三分冷 提交于 2020-02-25 04:49:10
问题 How can I make a method in Java which obtains input integer n , and an array of double x , and returns all combinations of n elements out of values in x. Where x={1,2,3} and n=2, the expected returns/combinations are {1,1},{1,2},{1,3},{2,2},{2,1},{2,3},{3,1},{3,2},{3,3} (the order is not ignored.) The number should be (int) Math.pow(x.length, n) e.g. static List<Double[]> getAll(int n, double[] x){ List<Double[]> combinations = new ArrayList<>(); //number of combinations should be x.length ^