permutation

N-th permutation algorithm for use in brute force bin packaging parallelization (containing the same item more than once)

筅森魡賤 提交于 2020-01-06 15:06:04
问题 I've written a small open-source 3D bin packaging library with a brute-force packager for use in real-time calculation of web shop order shipping cost. Many orders contain a small number of items, making brute-force a fair supplement to other algorithms. As orders can contain the same item more than once (i.e. repeated / duplicate / identical elements), I've gone with the lexographical permutations algorithm. Now I'm attempting to add some paralellization / multi-threading and have found a

itertools product to generate all possible strings of size 3

醉酒当歌 提交于 2020-01-06 13:06:45
问题 Input: pos_1= 'AVNMHDRW' pos_2= 'KNTHDYBW' pos_3= 'KVNGSDRB' Trying to find all possible triplets using one item from pos_1, one from pos_2, and one from pos_3 I'm trying to figure out how to use itertools.product(*) but I'm a little confused Ultimately, I want to create a list (or generator object) of all the different possibilities by taking one from pos_1 then one from pos_2 and then one from pos_3 Example output: 'AKK','ANV','WWB' pos_1 stands for position one and so on for pos_2 and pos

itertools product to generate all possible strings of size 3

ε祈祈猫儿з 提交于 2020-01-06 13:04:23
问题 Input: pos_1= 'AVNMHDRW' pos_2= 'KNTHDYBW' pos_3= 'KVNGSDRB' Trying to find all possible triplets using one item from pos_1, one from pos_2, and one from pos_3 I'm trying to figure out how to use itertools.product(*) but I'm a little confused Ultimately, I want to create a list (or generator object) of all the different possibilities by taking one from pos_1 then one from pos_2 and then one from pos_3 Example output: 'AKK','ANV','WWB' pos_1 stands for position one and so on for pos_2 and pos

How to compute derangement (permutation) of a list with repeating elements

放肆的年华 提交于 2020-01-06 01:18:48
问题 I have a list with repeating elements, i.e. orig = [1,1,1,2,2,3] . I want to create a derangement b = f(orig) such that for every location value in b is different from value in orig : b[i] != orig[i], for all i I know a solution when all element in orig are unique, but this is a harder case. Developing a solution in python, but any language will do. 回答1: The not so-efficient solution is clearly import itertools set([s for s in itertools.permutations(orig) if not any([a == b for a, b in zip(s,

Encryption Program Changing Indexes of Strings

让人想犯罪 __ 提交于 2020-01-05 07:04:09
问题 public class Encryption { private static final int[] encrypt = {2, 9, 3, 4, 6, 8, 1, 0}; private static final int[] decrypt = new int[8]; private static final int minLength = 10; String encrypt (String password) { if(password.length()<minLength) { return password; } else { char[] arrayEncrypted = password.toCharArray(); for (int i = 0; i < encrypt.length; i++) { arrayEncrypted[i] = (char) (arrayEncrypted[i]); } return String.valueOf(arrayEncrypted); } } String decrypt (String password) { if

Why does the following code NOT generate permutations randomly? [duplicate]

南楼画角 提交于 2020-01-05 05:25:09
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What distribution do you get from this broken random shuffle? This is from Skiena's Algorithm Design Manual. Assume that myrand(a, b) generates a random number between a and b inclusive. The following code generates permutations uniformly at random for(int i = 0; i < n; i++) swap( a[i], a[myrand(i, n-1)]); whereas the following doesn't. for(int i = 0; i < n; i++) swap( a[i], a[myrand(0, n-1)]); The question is,

Generate all permutations of a list including diferent sizes and repeated elements

戏子无情 提交于 2020-01-05 05:10:20
问题 I wanted to create the function genAllSize ::[a] -> [[a]] , that receives a list l and generates all the lists sorted by size that can be built with the elements of the list l ; i.e. > genAllSize [2,4,8] [[],[2],[4],[8],[2,2],[4,2],[8,2],[2,4],[4,4],[8,4],[2,8],[4,8],[8,8],[2,2,2],[4,2,2],[8,2,2], ... How would you do it? I came up with a solution using permutations from Data.List but I do not want to use it. 回答1: Given an input list xs , select a prefix of that in a non deterministic way For

RegEx that matches only if a string contains a word from each list

筅森魡賤 提交于 2020-01-05 04:32:27
问题 I'm developing a software that has to check if a text contains a word taken from a specified list and a word taken from another specified list. Example: list 1: dog, cat list 2: house, tree the following texts has to match: the dog is in the house -> contains dog and house my house is full of dogs -> contains dog and house the cat is on the tree -> contains cat and tree the following examples must not to match the frog is in the house -> there is no word from the first list Boby is the name

Calculation of all possible mutations of a nonogram [closed]

亡梦爱人 提交于 2020-01-04 15:25:13
问题 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 years ago . I need to build a nonogram solver according to a very specific recipe. For each row, I need to calculate all possible mutations, and then check if that row would still make the puzzle valid. For those unknown with nonograms, here's a link. A row is nothing more than a boolean array, where 'true'

Search for any word or combination of words from one string in a list (python)

大憨熊 提交于 2020-01-04 10:10:21
问题 I have a string (for example: "alpha beta charlie, delta&epsilon foxtrot" ) and a list (for example ["zero","omega virginia","apple beta charlie"] ). Is there a convenient way to iterate through every word and combination of words in the string in order to search for it in the list? 回答1: Purpose You're saying combinations, but combinations are semantically unordered, what you mean, is you intend to find the intersection of all ordered permutations joined by spaces with a target list. To begin