permutation

A combination of a list given a length followed by a permutation in Prolog?

☆樱花仙子☆ 提交于 2019-12-23 12:04:20
问题 I need a predicate to return a list with all combinations of the input list, and the list result size is in the second param, the predicate would be like this permutInListN( +inputList, +lengthListResult, -ListResult), example: permutInListN([1,2,3],2,L). ? L=[1,2]. ? L=[2,1]. ? L=[1,3]. ? L=[3,1]. ? L=[2,3]. ? L=[3,2]. Combinations of [1,2,3] in a list L with length 2 . with no repetitions maybe using setoff. this is my code but it doesn't work at all , no generate all solutions

Generate all unique combinations from a vector with repeating elements

China☆狼群 提交于 2019-12-23 10:49:17
问题 This questions was asked previously but only for vectors with non-repeating elements. I was not able to find an easy solution to get all combinations from a vector with repeating elements. To illustrate I listed an example below. x <- c('red', 'blue', 'green', 'red', 'green', 'red') Vector x has 3 repeating elements for 'red' and 2 for 'green'. The expected outcome for all unique combinations would be like this. # unique combinations with one element 'red' 'blue' 'green' # unique combination

Can I make a Deterministic Shuffle in clojure?

你离开我真会死。 提交于 2019-12-23 07:29:51
问题 I'd like to make some shuffles of sets which will be the same every time my program is run: This is one way to do it: (def colours ["red" "blue" "green" "yellow" "cyan" "magenta" "black" "white"]) (defn colour-shuffle [n] (let [cs (nth (clojure.math.combinatorics/permutations colours) n)] [(first cs) (drop 1 cs)])) ; use (rand-int 40320) to make up numbers, then hard code: (def colour-shuffle-39038 (colour-shuffle 39038)) (def colour-shuffle-28193 (colour-shuffle 28193)) (def colour-shuffle

Algorithm for a stair climbing permutation

谁说胖子不能爱 提交于 2019-12-23 06:13:06
问题 I've been asked to build an algorithm that involves a permutation and I'm a little stumped and looking for a starting place. The details are this... You are climbing a staircase of n stairs. Each time you can either climb 1 or 2 steps at a time. How many distinct ways can you climb to the top? Any suggestions how I can tackle this challenge? 回答1: You're wrong about permutations. Permutations involve orderings of a set. This problem is something else. Problems involving simple decisions that

Permute rows and columns of a matrix

醉酒当歌 提交于 2019-12-23 05:19:47
问题 Assuming that I have the following matrix/array: array([[0, 0, 1, 1, 1], [0, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 0], [1, 1, 1, 0, 0]]) and I want to apply the following permutation: 1 -> 5 2 -> 4 the result should be in the end: array([[1, 1, 1, 0, 0], [1, 0, 1, 0, 0], [1, 1, 0, 1, 1], [0, 0, 1, 0, 1], [0, 0, 1, 1, 1]]) Now, an incredibly naive (and memory costly) way of doing so might be: a2 = deepcopy(a1) a2[0,:] = a1[4,:] a2[4,:] = a1[0,:] a = deepcopy(a2) a2[:,0] = a[:,4] a2[:,4] =

Finding all possible words from inputted character arrays (permutations)

天大地大妈咪最大 提交于 2019-12-23 05:11:51
问题 After reading through several posts I am still stumped with permutations and recursive functions. I am trying to create all possible 3 letter permutations of characters in an unequal length 2D array where the first letter is from the set {‘l’, ‘m’, ‘n’}, the second letter is from the set {‘q’, ‘r’} and the third letter is from the set {‘a’, ‘e’, ‘i’, ‘o’}. My code goes through the correct permutation pattern but does not print out the correct output. For example, if the first 8 permutations

Create all combinations of array children

我只是一个虾纸丫 提交于 2019-12-23 04:01:50
问题 I know this question popped up alot of times here. I did search before but didn't find anything that fits. I'm sitting here since like 5 hours and my brain is not getting me anywhere at the moment. D: I've got an array: [rahmenfarbe] => Array ( [0] => Graphite [1] => Aluminium [2] => Smoke ) [rueckenunterstuetzung] => Array ( [0] => PostureFit [1] => LumbalSupport ) [armauflagen] => Array ( [0] => Leder [1] => Vinyl ) [rollen] => Array ( [0] => Teppichrollen [1] => Hartbodenrollen ) And I

Create all combinations of array children

*爱你&永不变心* 提交于 2019-12-23 04:01:41
问题 I know this question popped up alot of times here. I did search before but didn't find anything that fits. I'm sitting here since like 5 hours and my brain is not getting me anywhere at the moment. D: I've got an array: [rahmenfarbe] => Array ( [0] => Graphite [1] => Aluminium [2] => Smoke ) [rueckenunterstuetzung] => Array ( [0] => PostureFit [1] => LumbalSupport ) [armauflagen] => Array ( [0] => Leder [1] => Vinyl ) [rollen] => Array ( [0] => Teppichrollen [1] => Hartbodenrollen ) And I

Creating permutations to reach a target number

我怕爱的太早我们不能终老 提交于 2019-12-23 03:27:06
问题 I have the array [1, 2, 4] and I want to make 4; I want it to return [4], not [[1,1,1,1], [1,1,2], [2,2], [4]], I was previously doing this but I started to run out of memory when running this on a small server. I had to let the whole function run through so I could .reverse() because the last time in the array was only useful to me. If we think of this in terms of currency, let's take [0.5, 0.5, 1, 0.2]; if I want $1, I want [1] and not [0.5, 0.5] because you always want the largest value

Creating permutations to reach a target number

帅比萌擦擦* 提交于 2019-12-23 03:27:03
问题 I have the array [1, 2, 4] and I want to make 4; I want it to return [4], not [[1,1,1,1], [1,1,2], [2,2], [4]], I was previously doing this but I started to run out of memory when running this on a small server. I had to let the whole function run through so I could .reverse() because the last time in the array was only useful to me. If we think of this in terms of currency, let's take [0.5, 0.5, 1, 0.2]; if I want $1, I want [1] and not [0.5, 0.5] because you always want the largest value