What is the value of k after the following pseudocode has been executed?k := 0for i1 := 1 to n1 k := k + 1for i2 := 1 to n2 k := k + 1 ... for im := 1 to nm k := k + 1...Read more

Was reading about the 8-Queen problem here - http://en.literateprograms.org/Eight_queens_puzzle_%28C%29It says 'For eight queens, this solution considers 64^8 or 281474976710656 different solutions'. Since every consecutive queen will have one less position to consider during its placement on the board, shouldn't that total number of solutions be - (64-1)*(64-2)...(64-8)?...Read more

I'm trying to find an algorithm which "breaks the safe" by typing the keys 0-9. The code is 4 digits long. The safe will be open where it identifies the code as substring of the typing. meaning, if the code is "3456" so the next typing will open the safe: "123456". (It just means that the safe is not restarting every 4 keys input).Is there an algorithm which every time it add one digit to the sequence, it creates new 4 digits number (new combinations of the last 4 digits of the sequence\string)?thanks, km.Editing (I post it years ago):The quest...Read more

So I'm having trouble with these two problems, and have kind of started them but not sure if I'm on the correct track. (I'm using the combination and permutation formulas)Problem 1: "A group of students contains five men and six women.""I go to the store to buy hats for the eleven students. Hats come in four colors: red, blue,green, and yellow. How many different ways can I buy the hats, if I have to buy at least one hateach color?" This is how I'm going about the problem:Total ways buy hats with 1 of each color = Total ways of buying hats - To...Read more

I am trying to find all possible permutations of a character string and all their substrings.For example given the input 'abc' the function should return:['a', 'b', 'c', 'ab', 'ac', 'ba', 'bc', 'ca', 'cb', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba']I've been trying for hours on end and couldn't find any solution. Didn't find any related question either. A C# or Java solution would be prefered but it doesn't matter much. Pseudocode would be fine too....Read more

The magician Meg is a little puzzled. She has three white rabbits, two black rabbits and one green rabbit. She wants them in a nice line where two rabbits of the same colour never are directly beside each other. How many such lines exist. You may assume that rabbits of the same colour are identical....Read more

I'd like to know a possible algorithm to calculate all possible combinations, without repetitions, starting from length=1 until length=N of N elements.Example:Elements: 1, 2, 3.Output:123121323123...Read more

We are given 3 variables, d, a and b.d specifies the maximum number of places.a and b specify the minimum digit and maximum digit respectively.We have to find how many numbers can be made each of which has its digits in non-decreasing order, with maximum d places, and each digit between a and b, both inclusive.Ex-d = 1a = 8b = 9Answer = 2 (Possible numbers are 8 and 9)Ex-d = 2a = 8b = 9Answer = 5 (Possible numbers are 8, 9, 88, 89, and 99)I have tried applying, permutation and combinations, but could not come across a generic answer for all val...Read more

No.of ways of selecting 4 different numbers from the set A={1,2,3,4,..,18} whose sum is 31.I know combinations with multinomial theorem but here we want distinct no.s.How to eliminate the ways of getting 2 or 3 no.s repeated....Read more

I currently have a problem that for my senior year, I need to choose 5 elective courses out of 20+ possible courses. All these courses are distributed to weekdays. I need to develop a robust algorithm to show me all possible combinations without overlapping any of the course hours. I am a little bit short of time, so I figured I'd ask here, and it would be of help to other people in the future.My original idea was to try all combinations of 5 out of 20+, and remove the schedules that had overlapping courses. The brute force solution seems easy ...Read more

I have the following problem. Given a set S of n elements, I need to generate all the possible combinations with repetitions disregarding order of sizes k=1,2,...,m.Example:n =3S = {1,2,3}All the possible combinations are:k=1: 1,2,3k=2: 11, 12, 13, 22, 23, 33k=3: 111, 112, 113, 122, 123, 133, 222, 223, 233, 333.k=4: 1111, 1112, 1113, ......k=m: ...Clearly, combinations at step k can be computed using the combinations obtained at k-1.What is the best algorithm (pseudocode) and its complexity to get all combinations for all k....Read more

I'm trying to generate code which will take the components (i.e, a-f) of various combination permutations (combo) one, two, three, or four units long using these six components and provide various non duplicating combinations of combinations (combo.combo) which contain all of the components (i.e., [ab + cdef and ac + bde + f] but not [ae + bc + df and aef + bc + d]). It would be nice if this code could allow me to 1) input the number of components, 2) input the min and max unit length per combo, 3) input the min and max number of combos per com...Read more

The matrix NxN has N rows and columns. It has all unique elements starting from 1 to (N^2). The condition is the summation of any row elements should be equal to summation of any other row or column elements.Example: For 3x3 matrix, one of the possible combination looks like following.4 8 32 6 79 1 5 Now the question is how many possible combinations can occur to satisfy the given condition of given NxN matrix where N is any odd number?Thanks for the help in advance.Patrick...Read more

I have 1-9 digit number and want to generate probability (combination) of number without duplicate and with duplicate.int[] array = {1, 2, 3, 4};I need the output to be like this:{1,2}{1,3}{1,4}{2,1}{2,3}{2,4}{3,1}{3,2}{3,4}{1,1}{2,2}{3,3}{4,4}...Read more

I have a word corpus of say 3000 words such as [hello, who, this ..].I want to find the nth 3 word combination from this corpus.I am fine with any order as long as the algorithm gives consistent output.What would be the time complexity of the algorithm.I have seen this answer but was looking for something simple....Read more