For example I've array generated with the loop like this.  var array=[]; for(var i=1; i&lt;=30; i++)   {    array.push(i);    }  console.log(array);   I want to output the combination of all the possible group of 7 numbers from the array. For example a sample output may look like : [1,5,14,4,30,23,19]. If I would to calculate the possible combination with the combination formula. It would be something like this: n!/r!(n-r)!  And it is going to be a huge number. I've found a  ,  but what it does is that it prints out all the possible numbers according to the length of array. But my need is to find out the possible combination of 7 numbers from total 30 integers.  How would I solve this problem logically and practically with javascript.
24385
I want to write a function that takes an array of letters as an argument and a number of those letters to select.   Say you provide an array of 8 letters and want to select 3 letters from that. Then you should get:  8! / ((8 - 3)! * 3!) = 56   Arrays (or words) in return consisting of 3 letters each.
112190
This question is a part of a TopCoder problem. I am learning algorithms, and just got stuck at this (not homework).  Suppose we have a set $A$ of integer elements, such that $n(A) = a$ (number of elements in $A$ is $a$). Now we have some $n$ blanks, each of which can be filled using the $a$ elements in A, repetition allowed. I want to find out the total number of such sequences of length $n$ which are in non decreasing order, and can be formed using the elements in $A$.  My thoughts reduce this problem to a dynamic programming approach, but I just wanted to find out if a straightforward formula is possible or not. Thanks.
9888
I am using the algorithmic package (or even algorithm2e is fine). Is it possible to use curly braces to group some lines in the algorithm so as to be able to put an explanation to the right?
7059
Assuming I'm asked to generate Fibonacci numbers up to N, how many numbers will I generate? I'm looking for the count of Fibonacci numbers up to N, not the Nth number.  So, as an example, if I generate Fibonacci numbers up to 25, I will generate:   1, 1, 2, 3, 5, 8, 13, 21 that's 8 numbers   How do I calculate this mathematically for an arbitrary "n"?
4181
What's the best way to break from nested loops in Javascript?  //Write the links to the page. for (var x = 0; x &lt; Args.length; x++) {    for (var Heading in Navigation.Headings)    {       for (var Item in Navigation.Headings[Heading])       {          if (Args[x] == Navigation.Headings[Heading][Item].Name)          {             document.write("&lt;a href=\""                 + Navigation.Headings[Heading][Item].URL + "\"&gt;"                 + Navigation.Headings[Heading][Item].Name + "&lt;/a&gt; : ");             break; // &lt;---HERE, I need to break out of two loops.          }       }    } }
59225
What is the number of strings at size $n$ that is constructed from ${a,b,c,d}$ and there is an even num of $a$?  I have tried to answer it as recursion formula in the following logic:  In order to build $ A(n) $, I will split into several cases:   if the string starts with $a$, then I will need another $a$ to make an even number of $a's$. so we get $aa[A(n-2)]$ meaning 2 $a's$ at the start + a valid string at the size of $n-2$. if it starts with $b,c,d$ we get $b[A(n-1)]$ + $c[A(n-1)]$ +$d[A(n-1)]$, meaning a one of the letters + a valid string at the size of $n-1$.   So we will get a recursion formula that looks like that:  $A(n) = A(n-2) + 3A(n-1)$  I'm not 100% on my answer, am I right to approach it in that direction?
43812
Let's say I have numbers each taken in a set $A$ of $n$ consecutive naturals, I ask myself : how can I found what are all the unique multisets, which could be created with $k$ elements of this set $A$?  For example I've got $A=[1,2,\dots,499]$. If I wanted to create unique multiset of 3 elements, I would search all the multisets $\{a,b,c\}$ such as $a\leq b\leq c$ and then have all the unique multisets. As such for each elements $a$ there is $499-(a-1)=500-a$ possibilities for $b$ and $500-b$ possibilities for $c$. Unfortunately I'm stumped here and can't find the number of possible combination, as I didn't do any maths for years. I know that I should have some kind of product, but I don't know how to find the product anymore.  So first, I would like to know if I am right in my original assumption, or if I am looking in the wrong direction. Second I would like to approach that as if I were doing an homework, as I would like to understand the logic behind it: What would be the formula to give the numbers of multisets of $k$ elements from a set $A$ of $n$ consecutive naturals?  P.S. I'm totally new to math.SE, as such, I'm not sure I tagged the post appropriately.
77774
That is, if I had two or more sets, and I wanted to return a new set containing either:   All of the elements each set has in common (AND). All of the elements total of each set (OR). All of the elements unique to each set. (XOR).   Is there an easy, pre-existing way to do that?  Edit:  That's the wrong terminology, isn't it?
119250
Given a set of whole numbers of size $n$, how many unique combinations of these whole numbers are there?   For example, for the set $\{1,2,3\}$ the unique combinations are   $\{1,2,3\}, \{1,2\}, \{1\}, \{2\}, \{3\}, \{2,3\}, \{1,3\}$   The number of combinations for $\{1,2,3\}$ is $7$.  Does this generalize to the number of unique combinations in a set is $2^n-1$ where $n$ is the number of elements in the set?
116007
In , is the following the only way to get the number of elements?  arr.__len__()   If so, why the strange syntax?
52907
I was reading up on the Fibonacci Sequence,  $\text {{1,1,2,3,5,8,13,....}}$ when I've noticed some were able to calculate specific numbers. So far I've only figured out creating an array and counting to the value, which is incredibly simple, but I reckon I can't find any formula for calculating a Fibonacci number based on it's position.  Is there a way to do this? If so, how are we able to apply these formulas to arrays?
57035
If I want to find how many possible ways there are to choose k out of n elements I know you can use the simple formula below:  $$ \binom{n}{k} = \frac{n! }{ k!(n-k)! } .$$  What if I want to go the other way around though?  That is, I know I want to have $X$ possible combinations, and I want to find all the various pairs of $n$ and $k$ that will give me that number of combinations.  For example, if the number of combinations I want is $3$, I want a formula/method to find that all the pairs that will result in that number of combinations are $(3,1)$ and $(3,2)$  I know I could test all the possible pairs, but this would be impractical for large numbers.  But perhaps there's no easier way of doing this then the brute force approach?
7374
I'm designing an algorithm to do the following: Given array A[1... n], for every i &lt; j, find all inversion pairs such that A[i] &gt; A[j]. I'm using merge sort and copying array A to array B and then comparing the two arrays, but I'm having a difficult time seeing how I can use this to find the number of inversions. Any hints or help would be greatly appreciated.
11919
I have a string ABCCEF and I want to find the number of permutations not counting the duplicates. I ran a piece of python code     len(set([''.join(i) for i in itertools.permutations('ABCCEF')]))   and the output was 360. This piece of code determines all the permutations of ABCCEF (including the duplicates), creates a set of the permutations, then spits out the length of that set.  I am really rusty in the subject of combinatorics but through the magic guess and check, I BELIEVE that the value 360 is determined from  5*4*3*3*2*1 = 360   I determined this from the string have 6 values but only 5 unique values. So on the first slot I have 5 options to choose from, then 4, then 3. then 3 again (2 C's), then 2, then 1.  I dont really have a firm grasp of this concept. I was wondering if anyone could point out flaws in my logic and/or help me with a better process to solve this problem. Pretty much explain to me why I am correct...OR WRONG!
118252
Given $n$ symbols and an integer $k &gt; 0~(k \leq n)$, find the number of all distinct strings of length $n$, formed by any $k$-out-of-$n$ symbols, i.e., the target strings consist of exactly $k$ distinct symbols out of the given $n$ symbols. There are no restrictions on the number of repetitions allowed for each symbol.  Given $n$ and $k$, the goal is the derive a closed-form expression or upper and lower bounds on the count of all such (distinct) $k$-permutations.  Eg. Let S={a,b,c} be a set of n=3 elements. For k=2, the distinct 2-permutations of length 3 are: aab, aba, abb, baa, bab, bba, aac, aca, acc, caa, cac, cca, bbc, bcb, bcc, cbb, cbc, ccb. Hence, 18 distinct strings of length 3 are formed by 2-out-of-3 symbols.  Thanks for your help!
74245
In the  book on pg 130, they mention that an Array's length is fixed when you initialize it and that multidimensional arrays are not supported. I just tried using the .add function on an array and it worked so I'm sure what they are talking about, but I couldn't make an array of arrays (which could have just been because I didn't have the right syntax). Ignoring syntax errors, there seems to be some sort of difference and thus maybe an (even if just slight) advantage to using one over the other?
3799
How do I access the index in a for loop like the following?  ints = [8, 23, 45, 12, 78] for i in ints:     print('item #{} = {}'.format(???, i))   I want to get this output:  item #1 = 8 item #2 = 23 item #3 = 45 item #4 = 12 item #5 = 78   When I loop through it using a for loop, how do I access the loop index, from 1 to 5 in this case?