combinations

Delphi - Random Combination (Math)

丶灬走出姿态 提交于 2019-12-14 03:27:31
问题 I have a BIG problem here and do not even know how to start... In short explanation, I need to know if a number is in a set of results from a random combination... Let me explain better: I created a random "number" with 3 integer chars from 1 to 8, like this: procedure TForm1.btn1Click(Sender: TObject); var cTmp: Char; sTmp: String[3]; begin sTmp := ''; While (Length(sTmp) < 3) Do Begin Randomize; cTmp := IntToStr(Random(7) + 1)[1]; If (Pos(cTmp, sTmp) = 0) Then sTmp := sTmp + cTmp; end; edt1

Flex 3: Key press combination to trigger an event/function

空扰寡人 提交于 2019-12-14 02:43:07
问题 Within a specific canvas, I would like a user to be able to press a combination of keys which will trigger an event.(a bit like a cheat in an old megadrive game). Not sure where to start though. Anyone know if it is possible and if so could you give me a clue with how to start? Thanks in advance! 回答1: You can add an eventListener to the top level application for the KeyboardEvent.KEY_DOWN event and check for key combinations there. From this article: <mx:Application xmlns:mx="http://www.adobe

Permutations &/ Combinations using c++

无人久伴 提交于 2019-12-14 00:26:57
问题 I need a different version of permutations for my code. I could able to achieve what I want but it is not generic enough. my algorithm keeps going bigger along with my requirements. But that should not be. This is not a home work for any one, I need it for one my critical projects, wondering if any pre-defined algorithms available from boost or any other. Below is the standard version of next_permutation using c++. // next_permutation example #include <iostream> // std::cout #include

permutation ranking with DI sequence

爷,独闯天下 提交于 2019-12-13 20:27:39
问题 I want to rank and unrank through a subset of permutations given by length. The subset is definded as follows: Example for permutation length 4: We have the Input the Bitstring length 3 (always permutation length - 1) 010 0 means 2 consecutive elements are I ncreasing. 1 means 2 consecutive elements are D ecreasing. For this Bitstring exist the subset with following permutations: 1324 , 1423 , 2314 , 2413 , 3412 The bitstring defined subset of permutations i want to rank and unrank? Is there

Using combinations in python for very large sequences

自古美人都是妖i 提交于 2019-12-13 20:01:03
问题 I'm trying to determine all the combinations of 87 different strings that could make up a 29 element sequence. I was using combinations in python to do this and it works fine if the sequence is only 4 elements long but it can't handle 29. This is the code I'm using: combos = itertools.combinations(testv, 29) usable_combos = [] for i in combos: usable_combos.append(i) but the code fails at the loop stage. I assume this is some kind of memory issue but I'm not sure how to fix it. Any

generate a list of combinations/sets of numbers with limited supplies [closed]

允我心安 提交于 2019-12-13 18:57:51
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . Say I have 1 red ball, 1 blue ball, 2 yellow balls, and 3 green balls, for a total of 7 balls. I want to select 3 balls from the group of seven. How many ways can I do this? When I counted manually I got 11 combinations/sets. ie 123 124 133 134 144 233 234 244 334 344 444 What is an efficient way to generate and

What is an efficient code for generating n binary digit numbers with k bits set as one?

安稳与你 提交于 2019-12-13 17:25:01
问题 Is there any efficient code to generate numbers with n digits in their binary representation with exactly r bits set as one? Also is this a good strategy to generate masks for finding NcR combinations of a set? I've thought about generating all 2^n numbers and counting their bits but counting bits seems to be O(nlogn). 回答1: Well, if we are given a number with K bits set, how can we find the next largest number with K bits set? If we do this repeatedly we can generate all of them. Generating

List of combination between rows of diagonal block matrix

旧城冷巷雨未停 提交于 2019-12-13 15:25:22
问题 I have the following R matrix that is a combination of 2x3 and 3x3 submatrices and it can be more than 2 submatrices with different dimension (e.g. m1xp and m2xp and m3xp where each of m1,m2,m3 <= p) A2 <- list(rbind(c(1,1,1),c(-1,1,-1)), rbind(c(-1,1,1),c(1,-1,2),c(2,-1,2))) library(Matrix) A2 <- as.matrix(Matrix::bdiag(A2)) Rhs <- matrix(c(0,5,0.5,4),nrow = 4) beta <- c(rep(1.2,3),c(0.5,0.2,0.1)) > A2 [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 1 1 0 0 0 [2,] -1 1 -1 0 0 0 [3,] 0 0 0 -1 1 1 [4,] 0

Is there an R function to get the number of permutations of n objects take k P(n,k)?

余生长醉 提交于 2019-12-13 11:42:12
问题 ..or do I have to give P.nk <- factorial(n) / factorial(n-k) or P.nk <- choose(n,k) * factorial(k) Thank you. 回答1: I don't know of any existing function. Your first suggestion will fail with large n. Your second idea should work fine when written as a function: perm <- function(n,k){choose(n,k) * factorial(k)} Then perm(500,2) will give 249500 for example. 回答2: I think the gregmisc package provides these functions. library(gregmisc) permutations(n=4,r=4) Mailing list reference: [R]

Combinations of 2 lists [duplicate]

一笑奈何 提交于 2019-12-13 11:21:50
问题 This question already has answers here : Python How to pair two list by lambda and map (5 answers) Closed 2 years ago . Input: [1, 2, 3] [a, b] Expected Output: [(1,a),(1,b),(2,a),(2,b),(3,a),(3,b)] This works, but is there a better way without an if statement? [(x,y) for (x,y) in list(combinations(chain(a,b), 2)) if x in a and y in b] 回答1: Use itertools.product, your handy library tool for a cartesian product: from itertools import product l1, l2 = [1, 2, 3], ['a', 'b'] output = list(product