FAQ Database Discussion Community

## How many possible combinations of numbers make the same binary tree

python,algorithm,recursion,binary-tree,combinations
Setup: I have a list of numbers that represent a Binary tree. The first number is treated differently than some of the rest, it is the root. Out of "the rest" of the numbers, some will be higher than the root, some will be lower. Higher numbers are ordered to...

## R: Choosing specific number of combinations from all possible combinations

r,selection,combinations
Let's say we have the following dataset set.seed(144) dat <- matrix(rnorm(100), ncol=5) The following function creates all possible combinations of columns and removes the first (cols <- do.call(expand.grid, rep(list(c(F, T)), ncol(dat)))[-1,]) # Var1 Var2 Var3 Var4 Var5 # 2 TRUE FALSE FALSE FALSE FALSE # 3 FALSE TRUE FALSE FALSE...

## Find nCr mod M where M is not prime

combinations,modulo,inverse
I have to find nCrmod M where M is not a prime number. How can find that. I know that i need to find the inverse modulo but how it is going to be implemented if the number M is non-prime.

## On-demand algorithm to return successive combinations of k elements from n

algorithm,combinations
This post shows how to write an algorithm to spit out, at one time, all combinations of k elements from n, avoiding permutations. But how would one write an algorithm that, on demand, gives the next combination (obviously, without precomputing and storing them)? It would be initialized with the ordered...

## Cartesian product of numbers in a single list with given number (C#) [duplicate]

c#,list,combinations,cartesian-product,cartesian
This question already has an answer here: Generating a n-ary Cartesian product example 1 answer I just want to get cartesian product of numbers in a single list with specified number in C#. In below, I gave some examples of actually what I want get to: List<int> numbers =...

## Generate random pairs of numbers, without duplicates

java,arrays,random,combinations
I have to arrays with integers: int[] a={1,2,3,4,5}; int[] b={6,7}; I would like to generate an array, which contains pairs from the a and b arrays, in a random order, without duplicates. For example I would like to get the following result: c={(1,6),(2,7),(4,6),...} Thanks!...

## Compare one query with multiple results in PHP

php,sql,combinations
I have two text input. Like This: So, I have some kind of dynamic ajax search. I pass the input data and make two different mysql select. Something like this: Table finalmap - SELECT 1 id -------- latitud-----longitud--- 1 | 6.2523915 | -75.5737028 | 2 | 6.2640349 | -75.5990783 |...

## python connected combinations of list items

python,list,combinations
I have a list of values [1,2,3,4,5,...], I want to return a list of all possible connected combinations using list comprehensions, numpy or whatever works. By connected, i mean that pairs of items in the list should maintain their adjacencies in the combinations (not necessarily that integers with adjacent values...

## Return the different multiplicative combinations of a list of numbers in Python

python,combinations
I have a list of numbers and I wish to return a 2D list, preferably ordered from biggest to smallest (although I can do this afterwards), of all the possible combinations of multiplication (to yield the product of the original list) using all the elements of the list, without duplicates....

## Most suitable combinatorics algorithm

java,algorithm,combinations,combinatorics
There are 6 seats and 4 persons, for which seats must be allocated according to some optimality criterion. For example: Allocation 1: _ _ _ _ _ _ 1 2 3 4 Allocation 2: _ _ _ _ _ _ 1 3 2 4 ... Question 1: Which combinatorics problem...

## How to generate a matrix of vector combinations with zeros for excluded elements?

matlab,matrix,vector,combinations,vectorization
I want to create a matrix from all combinations of elements of one vector that fulfill a condition For example, I have this vector a = [1 2 3 4 5] and want to create a matrix like a = [1 0 0 0 0; 1 2 0 0 0;...

## Enumeration Combinations of K elements using Java 8

java,functional-programming,java-8,combinations
Given an instance of List<E>, using Java 8 features, how is it possible to build a List<List<E>> enumerating all possible combinations of k elements of the original List?

## Combinations of elements in an array

c,combinations
I'm trying to write a C program to find all the combinations of an given array and a specified length. This is what I've done so far.. #include <stdio.h> void com(int* a, int* t, int len, int i) { int j, k; if(len == 0) { for(k=0;k<3;k++) { printf("%d ",t[k]);...

## Number of all combinations in Knapsack task

algorithm,combinations,dynamic-programming
There is a classic Knapsack problem. My version of this problem is a little different. Given set of items, each with a mass, determine the number of combinations to pack items so that the total weight is less than or equal to a given limit. For example, there is 5...

## String Variations

python,string,combinations,variations
I have a string in python and a dictionary of 'rules', or possible alterations to the string. For example, one rule might have a key of 'he' and a value of 'e', or a key of 'll' and a value of 'l'. These rules would mean that any occurrence of...

## Subarrays in an array

javascript,arrays,algorithm,collections,combinations
I'm quite knew to JavaScript (been studying it only for less than a week now) and am having problems computing the sum of the values in the subarrays I generated from a certain array. I was able to do that using this function: function getSubs(arr) { var newarr = [];...

## Create combinations of a binary vector

r,binary,combinations
I would like to create all possible combinations of a binary vector made of a fixed number of 0 and 1. For example: dim(v)=5x1; n1=3; n0=2; In this case I'd like to have something like: 1,1,1,0,0 1,1,0,1,0 1,1,0,0,1 1,0,1,1,0 1,0,1,0,1 1,0,0,1,1 0,1,1,1,0 0,1,1,0,1 0,1,0,1,1 0,0,1,1,1 I found some help reading...

## generating combinations in Matlab

matlab,combinations
I have a column vector x made up of 4 elements, how can i generate all the possible combinations of the values that x can take such that x*x' is less than or equal to a certain value? note that the values of x are positive and integers. To be...

## Cycling through a vector whose elements are inputs to another function in R

r,functional-programming,combinations
I need to apply all the combinations of the elements of a vector to a particular function, and use these elements as inputs for this function as well. I would like it to be somewhat fast, but any combination of apply and its different flavors has proved fruitless so far....

## Converting recursive combination-finding algorithm to iterative to avoid GC Overhead Limit Exceeded error

java,recursion,garbage-collection,iteration,combinations
This algorithm's purpose is to generate a list of sequences of trips. Each trip has a start point and and end point. The user specifies both of those, and every sequence in the list returned by the algorithm must ultimately begin with a trip that has the specified start point...

## Getting combinations of multilevel arrays in ruby

arrays,ruby,combinations
a = [1,2,3,4].combination(3).to_a returns [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]] What do I need to do to get the following combination of the array shown below [["1a","1b"],2,3,4] should be => [["1a", 2, 3], ["1a", 2, 4], ["1a", 3, 4],["1b", 2, 3], ["1b", 2, 4],...

## Java KeyBindings Combination does not work

java,windows,events,combinations,keyevent
I'm struggling with creating a way to identify key combinations. Before I can even set any booleans, I noticed that certain key combinations lead to ignoring other keys. package question; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.KeyStroke;...

## Programmatically generate list of combinations other lists

python,list,combinations,dynamically-generated
I want to create a list of possible combinations of a list of lists (example will explain better) list=[[a,b],[c,d],[f]] The result should be acf adf bcf bdf The length of the list can vary, and the length of the lists within the variable list can also vary. How would I...

## R: generate possible permutation tables by one column

r,combinations,permutation
I have a table that looks like this: Indikaatori nimi Alamkriteerium Kriteerium Skoor 1 Indikaator 1 1.1 1 100 2 Indikaator 2 1.2 1 100 3 Indikaator 3 1.3 1 100 4 Indikaator 4 1.1 1 0 5 Indikaator 5 2.1 2 0 6 Indikaator 6 2.1 2 0 ......

## Algorithm to Generate number letter combinations with a twist

php,algorithm,numbers,combinations,letter
I have to generate a list of all possible combinations of numbers and letters of length three. The catch is on the first two characters can be letters or numbers, and the third one can only be numeric. For example: AA1, AA2, AA3 .... FC7 ... 001, 002 ... 365)...

## How to write a recursion function for all the possible parameter combinations in python

python,recursion,combinations
I am trying to write a piece of code to traverse all the possible parameter combinations for a algorithm with python. import numpy as np parameter={'alpha1':np.linspace(0.3,0.4,10),'alpha2':np.linspace(0.9,2,100),...'alpha5':np.linspace(5,10,100)} the problem is that I just couldn't write 5-nested for loop.Can anyone give a demo on how to write a recursion function to give...

## Generating addition combinations from an int list in python

I have an array of floats of unknown length. The numbers range from 0-1000. I'm looking to generate every possible addition combination from those numbers that is less than a user defined value and append them in another list. for example, if numlist =[200,350,510] and the defined maximum is 1200,...

## Brute force attack test on password for file

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...

## All possible N choose K WITHOUT recusion

algorithm,matlab,combinations
I'm trying to create a function that is able to go through a row vector and output the possible combinations of an n choose k without recursion. For example: 3 choose 2 on [a,b,c] outputs [a,b; a,c; b,c] I found this: How to loop through all the combinations of e.g....

## Find Number of combinations possible

java,math,combinations,permutation
There are two letters "X" and "Y". A String of length N needs to be formed using those two letters. How many number of combinations that can be possible where N should start with "Y" and no two or more consecutive "X" will be there? Consider N = 7: I...

## Make AUTO_INCREMENT reset itself on change of Parent ID

mysql,database,combinations,auto-increment
In a project assignment I have I want the one part of the PRIMARY KEY to reset after the other part changes value. For example: CREATE TABLE shopping_center( centerID INTEGER AUTO_INCREMENT, centerName CHAR(50), CONSTRAINT center_PK PRIMARY KEY(centerID)); CREATE TABLE staff( staffID INTEGER AUTO_INCREMENT, centerID INTEGER, name VARCHAR(50), CONSTRAINT staff_PK PRIMARY...

## Algorithm ,Finding combination from a list with n elements

java,python,c,algorithm,combinations
I want to write a function to select combination of k element from list of n element.I have the given source file in pdf form that i converted in text.And i got the following list .I was trying to use dfs to find the combinations but there are constraint that...

## formula for lotto combinations with fixed numbers?

algorithm,math,combinations
usually for lottery combinations the formula is "n! / (k!*(n-k)!)", e.g., for a 6/49 game it is "49!/(6!*(49-6)!)" is there a formula to calculate the same with m FIXED values (e.g., the numbers 1, 2, 3, and 4 are fixed) - 2 numbers are free for choice i thought the...

## C# console application that can find every combination of some numbers but only writes if they can divide by 3

c#,combinations
I have to perform a task. pls help me. İ want a c sharp console application that can find every combination of some numbers but only writes if they can divide by 3. We have 15 card in a bag. we will take 3 cards randomly(without replacement) . After that...

## Matlab - generating combinations of input and their sum

matlab,matrix,combinations,combinatorics,cartesian-product
I have to make a function that takes 3 inputs like e0, e1 and e2. The function will have 2 outputs x and y. x will be the combinations of e0, e1 and e2. y will be a column vector containing sums of columns of x. The following conditions must...

## R - row-wise combinations of two lists

r,list,combinations
assume that I have two lists of the same length. l1 <- list(c("a", "b", "c"), "d") l2 <- list(c("e", "f"), c("g", "h", "i")) Each row/element of a list can be seen as a specific pair. So in this example the two vectors c("a", "b", "c") c("e", "f") "belong together" and...

## R language cross-product combination of two string arrays

arrays,r,combinations
suppose I have two arrays a and b: a=seq(2013,2015) b=c('-03-31','-06-30') I would like to combine each element in a with each in b. The result should be an array which looks like: "2013-03-31" "2013-06-30" "2014-03-31" "2014-06-30" "2015-03-31" "2015-06-30" How do I do this?...

## finding the number of ways to generate a number

math,combinations,permutation
I am new to permutations and combinations. I am provided with the number n and I can make a number with the help of n+1 digits which are 0,1,...n. I need to find in how many ways I can make the sum n by putting these n+1 digits in n...

## How to bin all subsets of a python list into n bins

python,numpy,combinations,sympy,itertools
I have a list: a = range(2) and I am trying to get the list's contents binned into n(=3) bins, in all possible ways, giving (order not important): [[[],,], [[],,], [[],[0,1],[]], [[],[],[0,1]], [,,[]], [,[],], [,,[]], [,[],], [[0,1],[],[]]] So far, I have been using the sympy.utilities.iterables library, firstly to get all...

## Can't figure out what the generic name of this algorithm is called?

algorithm,recursion,dynamic,combinations,permutation
I just did a Top Coder SRM where there was a question I had problem solving. I am trying to searching online for details of the algorithm but I can't seem to find it. The question went around the lines of: You have an array, for example [12, 10, 4]...

## Counting in binary ruby

arrays,ruby,combinations
I have two arrays [a0 b0 c0] [a1 b1 c1] I want to calculate all the possible sums between the two. A possible sum consists of only 1 element for each column slot. For example a possible sum is a0 + b1 + c1 or a1 + b1 + c1...

## How to calculate the number of all possible combinations for a range of numbers from 1 to N?

python,math,combinations,itertools
Other than doing this: from itertools import combinations def brute_force(x): for l in range (1,len(x)+1): for f in list(combinations(range(0,len(x)),l)): yield f x = range(1,18) len(list(brute_force(x))) [out]: 131071 How could I mathematically calculate the number of all possible combinations? Is there a way to do it computationally without enumerating the possible...

python,combinations,permutation,probability
My approach to the problem was as follows- a=[ ] for i in range(7): a.append(*7) c=dict() for i in range(7): for j in range(7): a[i][j]=(i,j) for i in range(7): for j in range(7): c[i+j]=tuple((i*j+j+c)) print c But this produces: {0: (0, 0), 1: (1, 0), 2: (2, 0), 3:...

## Algorithm to print all combination of letters of the given string in lexicographical order

c++,string,combinations,powerset,lexicographic
I tried to create the code to generate all possible combination of the given string in the lexicographical order: The code that I wrote is: void get(char *n) { int l=strlen(n); sort(n,n+l); int k=0,m,i,j,z; while(k<l) { m=k; for(i=k;i<l;i++) { for(j=k;j<=i;j++) cout<<n[j]; cout<<"\n"; } for(z=m+2;z<l;z++) cout<<n[m]<<n[z]<<"\n"; k++; } } int main()...

## Generate all combinations of strings and their substrings in a set — python

python,string,set,combinations
I want to get all combinations of of strings from a set of strings. For Example: permut = set() permut.add("D") permut.add("C") def getAllKombos(stuff): returnvalue = set() for L in range(0, len(stuff) + 1): for subset in itertools.combinations(stuff, L): for i in subset: x = x + (str(i)) returnvalue.add(x) x =...

## Find all possibilities of bin and objects

algorithm,recursion,combinations
Given a finite set of bins and objects, where the bins are of infite size (there is no limit to the number of objects they can hold. What is an efficient algorithm to compute all the possibilities of objects in bins. For example: Lets say we have bins: B1, B2...

## Python combination with replacement

python,replace,combinations
Below is my code import itertools a = [1,2,3] for i in itertools.combination_with_replacement(a,3): print i Output (1, 1, 1),(1, 1, 2) (1, 1, 3),(1, 2, 2) (1, 2, 3),(1, 3, 3) (2, 2, 2),(2, 2, 3) (2, 3, 3),(3, 3, 3) Only 10 result is print out, but by formula,...

## Put array or string in this combination function PHP [closed]

php,arrays,string,function,combinations
With this function, i can have all possibles combination (with repetition). But, i doesn't want to put a string, i would like to put an array or something like this. Maybe if I can put in \$source="apple,patatoes,orange"; And split in the function to have this result : apple,apple apple,patatoes apple,orange...

## Combinatorial Optimization - Fewest Columns in Matrix

optimization,combinations
I'm trying to resolve, obtain a algorithm, for the problem that follows: Having a matrix with n columns and each column is the same length, what's the minimum number of columns so I can get all values of the matrix. Ex: Matrix with 4 columns and 3 rows with values...

## how do I generate set of all tokens of length exactly equal to 8

c,algorithm,combinations
I need to generate complete set of tokens of size exactly equal to 8.Each bit in the token can assume values from 0 - 9 and A -Z. For example- The following are valid tokens: 00000000 0000000A 000000H1 Z00000XA So basically i want to generate all tokens from 00000000 to...

## How to get all combinations from multiple arrays?

php,arrays,matrix,combinations
Supposing I have these 3 arrays \$array1 = array(1,2); \$array2 = array(4,5); \$array3 = array(7,8); I need this output 1 4 7 1 4 8 1 5 7 1 5 8 2 4 7 2 4 8 2 5 7 2 5 8 One of my problems is that my...

## Generate a list of unique combinations from a list

I want to generate a list of all unique ways to choose two from a list of numbers in Haskell. So from the list [1,2,3] I would like [[1,2],[2,3],[1,3]]. Order is not important so I want to avoid producing both [1,2] and [2,1] for example. My current solution is: pairs...

## function to select combinations of characters from a string in c++

c++,string,character,combinations
so here is my problem: I need a function that given a string "qwer" of random length can select and put in an array all the possible sequences of characters long from 1 up to the length of the string. I am sorry, it is difficult to explain, but i...

## Combine two or more columns into one in a table

sql-server,data-structures,combinations
I have an existing database with a table that I need to alter. Due to some recent changes requested, I need to take two columns out of a table and put the data from those two columns into an existing column in the table. Thankfully, they are all Varchar type...

## find all possible combinations of N non-repeating numbers within a certain range that add up to X

javascript,php,algorithm,numbers,combinations
i have been trying to find a solution to this for several months now. it is for an art project of mine. so far i could find partial python and c solutions, but they are of no use for my case... i need a working solution either in PHP or...

## R Geospatial Aggregation: Collapsing Directionality without Using Forloop (Remove Duplicates)

r,combinations,aggregation
I am trying to perform aggregation (basic sum) on geospatial data that contains directionality information. I am trying to collapse the directionality dimension. So if A -> B and B -> A, then count both. I have the following data: u <- data.frame(str_statn=c(42, 106, 3, 6, 4), end_statn=c(106, 42, 6,...

## PHP replace symbols all possible variants

php,replace,combinations
I have array symbols what I want replace, but I need generate all possibillity \$lt = array( 'a' => 'ą', 'e' => 'ę', 'i' => 'į', ); For example if I have this string: tazeki There can be huge amount of results: tązeki tazęki tązęki tazekį tązekį tazękį tązękį My...

## Finding # of combinations of truth values

java,boolean,expression,combinations
There is a question I have had a problem doing. How many combinations of truth values for p, q, and r make this expression true? (p && !q) || (q || !r) I know that the answer is 7, but I don't know how they got the answer. I could...

## Finding all possible combinations of a given array in Java

java,arrays,combinations
I'm working on a problem in Java to find all possible combinations given an arbitrary starting array, by decrementing the values one at a time of each item in the array until the value 1 is reached at each index. I've started on the below test case but haven't got...

## Every (specific sized) combination from set/array with no duplicate items

php,arrays,combinations,permutation
Let's say I have set = [1, 2, 3, 4, 5, 6, 7] I'd like the following in return [1, 2, 3, 4, 5] [4, 3, 2, 1, 6] [7, 5, 1, 3, 2].......... Essentially, as the title states I'm looking to generate specific sized combinations from an array but...

## Algorithm to get all the combinations of size n from an array (Java)? [closed]

java,combinations,combinatorics
Right now I'm trying to write a function that takes an array and an integer n, and gives a list of each size n combination (so a list of int arrays). I am able to write it using n nested loops, but this only works for a specific size of...

## Postgresql enforce unique two-way combination of columns

postgresql,unique,combinations
I'm trying to create a table that would enforce a unique combination of two columns of the same type - in both directions. E.g. this would be illegal: col1 col2 1 2 2 1 I have come up with this, but it doesn't work: database=> \d+ friend; Table "public.friend" Column...

## To find all possible combinations of strings present in a column range (order does not matter ,repetition not allowed)

excel,excel-vba,combinations
I want to get all possible combinations of certain values present in a column range and print them in an excel sheet: Please note that the order of combination does not matter i.e AB=BA Here is an example of data in column1 for which combinations are to be found: F1...

## Python every possible combination of a string

python,string,recursion,combinations,permutation
Hi so I'm working with python and I'm trying to write a method where given a string, it would find every combination of that string and append it to a list. I'll give the string and show the outcome that I want. string: x = 'god' outcome: lst = ['g',...

## test all combination (c++)

c++,combinations
I assume this is a classic question but I did not find an answer that fit my problem. I have two vectors of 'MyObject' and I want to iterate through all possible combination of the elements of the first vector with those of the second one, and treat all cases...

## SQL list all rows where column A appears more than once but have distinct Column B values

sql,ms-access,combinations,distinct-values
I have two columns for example, I want to list all the rows where the items in ROW A appears more than once in Column A, but have distinct values in Column B. So far I have not figured out an answer Column A Column B Apple x Banana a...

## Combination to be produced with condition in R [closed]

r,combinations
Hi I have 4 strings to execute combinations- 1)PES 2)PEA 3)PAL 4)PSL I have to write a script to perform combination (combinatorial - ncr formula) such that I only need combination with following algorithm If I have PAL in the combination output then keep PAL only and remove other string...

## Generating all combinations without repetition using MATLAB

matlab,combinations
i have 4 sets each contain 6 elements from which I want to generate all possible vectors of size 8 were the first two elements are from set1 second 2 from set2 third 2 from set3 forth 2 from set4 without repetition in the points taken from each set such...

## Add functionality to an existing event listener

javascript,jquery,events,javascript-events,combinations
I've got a set of inputs on a form that are watched for interactivity, validation, or both. In the case of both, I'm not sure how to add the second set of functionality without overriding the prior assignment. Here's an example. I've got a field that should be watched for...

## PostgreSQL combinations as distinct from permutations

sql,arrays,postgresql,combinations,permutation
Can't figure out how to make combinations of arrays without repetitions. INPUT is an array of n variables LIKE '{A,B,C,D,E}' Variable A is always single array LIKE '{"A"}' or '{"D,C"}' or '{"D,A,B"}' etc.. What I need is to combine INPUT with A(i) EXAMPLE: 1. A = '{"B"}' --> att='{"B,A","B,C","B,D","B,E"}' 2....

## Algorithm for generating “anti-Gray” on-demand combinations of k elements from n

algorithm,sorting,combinations,combinatorics,gray-code
I'm trying to implement an algorithm to get all combinations of k elements out of a set of n elements where the difference between two consecutive combinations are maximized (so kind of reverse Gray codes). In other words, the combinations should be ordered to avoid elements from appearing twice in...

## All combinations of vector and its negatives in R

r,vector,combinations
How can I find all combinations of a vector and it's negatives in R? I.E. x <- c(1,2,3,4) will output (1,2,3,4), (-1,2,3,4), (1,-2,3,4), (1,2,-3,4), (1,2,3,-4), ... , (-1,-2,-3,-4) ...

## I want to expand.grid from each row of a matrix when the matrix could have variable number of rows

r,matrix,combinations
myMatrix <- matrix(c(1,2,3,4,5,6),2,3, byrow=T) # line 1 exp.myMatrix <- function(myMatrix) { # line 2 for (rownum in 1:nrow(myMatrix)) assign(paste("R",rownum, sep=""), myMatrix[rownum,]) # line 3 Combinations <- do.call(expand.grid, lapply(ls(pattern='^R\\d\$'), get)) # line 4 rm(list=ls(pattern='^R\\d\$')) # line 5 return(Combinations) # line 6 } # line 7 Combinations <- exp.myMatrix(myMatrix) # line...

## List all combination possible in a php array of boolean value in PHP

php,arrays,function,combinations
I will try to better explain my needs. I need to generate from scrach, a multidirectional array who contain many array. The inner array must be array containing 7 boolean value. I need to have all the combinaisons possible of 7 boolean values. With 7 cases, it make 128 inner...

## Permutations and grouping in R

r,combinations,permutation
Assume in R we have three columns. The first is a random sample of 1:4 with replacement. The second is 1:4 repeating as needed. The third is just an index. The result should output a pasted combination of the numbers where order doesn't matter and give a count. Please, note...

## Fastest solution to list all pairs of n integers?

performance,matlab,matrix,combinations,combinatorics
I want to list all possible pairs of the integers [1, n] with a large n. I find myself looking for the fastest option. This is what I've come up with so far. Matlab's nchoosek and combnk methods recommend n<15 for listing all possible combinations because of the explosive number...

## My recursion of getting subset doesn't print out the right answer

algorithm,recursion,combinations,subset
I am trying to implement a method to get all subset of a set. I understand the logic of doing that. i.e. Subset(n) = n + Subset(n-1), but the code I wrote keep printing out the wrong answers. Here is my code: void subset(vector<int> &input, vector<int> output, int current) {...

## Java Program to compute nCr throwing Arithmetic Exception “Divide by zero”

java,algorithm,combinations
Following code tries to compute the nCr values for the various values of given n and here r varies from 0 to n. The input is in the following format :- Input Format The first line contains the number of test cases T. T lines follow each containing an integer...

## Handling events for mouse click and keydown or keypress (for non-modifier keys)

javascript,events,click,combinations,keypress
I am new to JS and trying to learn on my own - thanks for any help! I am trying to have a simple program respond to a click differently depending on what other key is pressed at the time of the mouse click. I have searched far and wide...

## PostgreSQL find all possible combinations (permutations) in recursive query

sql,postgresql,combinations
Input is an array of 'n' length. I need to generate all possible combinations of array elements, including all combinations with fewer elements from the input array. IN: j='{A, B, C ..}' OUT: k='{A, AB, AC, ABC, ACB, B, BA, BC, BAC, BCA..}' With repetitions, so with AB BA.. I...