permutation

combinations with two elements

不想你离开。 提交于 2020-01-13 05:07:06
问题 With python. It's possible to permute elements in a list with this method: def perms(seq): if len(seq) <= 1: perms = [seq] else: perms = [] for i in range(len(seq)): sub = perms(seq[:i]+seq[i+1:]) for p in sub: perms.append(seq[i:i+1]+p) return perms if a list is: seq = ['A', 'B', 'C'], the result will be.. [['A', 'B', 'C'], ['A', 'C', 'B'], ['B', 'A', 'C'], ['B', 'C', 'A'], ['C', 'A', 'B'], ['C', 'B', 'A']] HOW TO modify this method, to make permutations two terms a time? I mean, if the list

Permutation of a 2 dimensional arraylist

梦想的初衷 提交于 2020-01-13 04:26:09
问题 I'm trying to make a 2 dimensional array list that is filled with every possible combination of lets say 1,2,3,4 recursively. with no double ups. for example. 1,0,0 2,0,0 3,0,0 4,0,0 1,2,0 1,3,0 1,4,0 1,2,3 etc... so far I have //this gives me all my numbers for(int i =0;i<arraySize;i++) index[i] = i; // and is the part that make the combinations for(int i = 0;i<arraySize;i++){ for(int x = 0;x<k;x++) combinations.get(i).set(x, index[i]); EDIT: Also I'm not trying to print the result I want to

How to make all of the permutations of a password for brute force?

倾然丶 夕夏残阳落幕 提交于 2020-01-12 15:48:18
问题 So I was trying to make a program that brute forces passwords. Firstly, I made a program for a password of length 1: password = input('What is your password?\n') chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' def brute_force(): for char in chars: if char == password: return char print(brute_force()) Then I edited it for a password of length 2: def brute_force(): guess = [None, None] for char in chars: guess[0] = char for char2 in chars: guess[1] = char2 if ''.join

How to make all of the permutations of a password for brute force?

血红的双手。 提交于 2020-01-12 15:47:06
问题 So I was trying to make a program that brute forces passwords. Firstly, I made a program for a password of length 1: password = input('What is your password?\n') chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' def brute_force(): for char in chars: if char == password: return char print(brute_force()) Then I edited it for a password of length 2: def brute_force(): guess = [None, None] for char in chars: guess[0] = char for char2 in chars: guess[1] = char2 if ''.join

N choose N/2 sublists of a list

馋奶兔 提交于 2020-01-11 06:36:06
问题 Is there an efficient way in Python to get all partitions of a list of size n into two subsets of size n/2 ? I want to get some iterative construct such that each iteration provides two non-overlapping subsets of the original list, each subset having size n/2 . For example: A = [1,2,3,4,5,6] # here n = 6 # some iterative construct # in each iteration, a pair of subsets of size n/2 # subsets = [[1,3,4], [2,5,6]] for example for one of the iterations # subsets = [[1,2,5],[3,4,6]] a different

Python: find all possible word combinations with a sequence of characters (word segmentation)

时光毁灭记忆、已成空白 提交于 2020-01-11 06:17:08
问题 I'm doing some word segmentation experiments like the followings. lst is a sequence of characters, and output is all the possible words. lst = ['a', 'b', 'c', 'd'] def foo(lst): ... return output output = [['a', 'b', 'c', 'd'], ['ab', 'c', 'd'], ['a', 'bc', 'd'], ['a', 'b', 'cd'], ['ab', 'cd'], ['abc', 'd'], ['a', 'bcd'], ['abcd']] I've checked combinations and permutations in itertools library, and also tried combinatorics. However, it seems that I'm looking at the wrong side because this is

Permutation Javascript

孤者浪人 提交于 2020-01-10 05:40:07
问题 So I have this code now, and in input I have in ascending order my name's letters "ahimrsu". I need to show up the right number for "mariush" from all combinations which should to be 2170. For now it only show ahimrsu, ahimrus, ahimsru, ahimsur, ahimurs, ahimusr, ahirmus, ahirmsu.... etc How can I do this? <!DOCTYPE HTML> <html> <head> <!--Script Function Start Here--> <script type="text/javascript"> function perms(data) { if (!(data instanceof Array)) { throw new TypeError("input data must

Array of all RGB permutations in PHP

让人想犯罪 __ 提交于 2020-01-07 04:33:09
问题 I am trying to make an array of all the possible colours made out of RGB values. Every permutation between r=0 b=0 g=0 to r=255 b=255 g=255. The idea of my function is that when it's called you supply a limit number so that the function returns an array of RGB values up to this number to stop it returning all 16 million. The code I have below returns 767 permutations (256 * 3) how do I get this to return the full 16 million up to the limit number I provide? function colourArray($number) { $r

Clean algorithm to generate all sets of the kind (0) to (0,1,2,3,4,5,6,7,8,9)

心不动则不痛 提交于 2020-01-06 21:51:11
问题 Basically, I'd like a set of sets that contains from (0..9), then (0, 1..9), (1, 2..9)..(8,9), and so on and so forth up until (0,1,2,3,4,5,6,7,8,9). I know this can be accomplished by nesting for loops in the manner below, but I'm wondering if there's a neater way of doing it? Preferably something that could be accomplished within C#, but I'm interested in any algorithm. for (int i = 0; i < max; i++) { yield {i}; for (int j = i + 1; j < max; j++) { yield {i, j}; for (int k = j + 1; k < max;

Is there any way to do permutation of more than 11 components?

杀马特。学长 韩版系。学妹 提交于 2020-01-06 19:46:34
问题 I am trying to generate all the sequences of a given variable with some precedence constraint. For example, if we have five objects, [1 2 3 4 5] , then there are 5! = 125 ways to permute those. However, if we impose some precedence constraints like: a) The sequence should always start from 1. b) After 1 only 2 or 3 can be attached. c) 4 can come after 5 or 3 d) 5 can come after 4 or 2 only these possibilities remain: 1 2 3 5 4, 1 2 3 4 5, 1 2 5 4 3, 1 2 5 3 4, 1 3 4 5 2, 1 3 4 2 5, 1 3 2 5 4,