I'm trying to figure out how many possible ways there are to combine various elements form this string.
"{Hello|Hi|Hey} {world|earth}{!|.|?}"
Where one item (separated by a pipe/|) is selected at random from each group ({}) and combined into a single string.
So the above "template" could produce:
Hello world.
Hi earth?
Hey world.
Hi...
I am trying to write an algorithm to calculate outcomes. But I need help with combinatorics.
Suppose I have to choose 2 numbers from 1 to 10.
From the fundamental rule of counting, in the absence of any restriction, the number of possible outcomes is 10 * 10 = 100. (10 possible outcomes in choosing the first number x 10 possible outcom...
Is there a built in method in a java library that can compute 'N choose R' for any N, R?
...
What are the no of combinations in which 8 persons taking part in a knockout tornament play? Total no of matches played would be 7 but I also need the number of combinations that can for this set
...
I have an unknown number of arrays, each containing an unknown number of words. I want to concatenate the values from each list so that all possible variations of the words are stored to a final array.
For example, if array 1 contains:
dog
cat
and array 2 contains:
food
tooth
and array 3 contains:
car
bike
I'd like the output t...
I just tried for my first programming interview and one of the questions was to write a program that given a 7 digit telephone number, could print all possible combinations of letters that each number could represent.
A second part of the question was, what about if this was a 12 digit international number? How would that effect you de...
Does anyone have Java code for generating all VARIATIONS WITH REPETITION?
There are plenty of permutation and combination examples available, and variations must be the easiest one...
It feels stupid to waste time to reinvent the wheel (it must be plenty of code written for this).
An example of VARIATIONS WITH REPETITION could be like...
Hi,
I have just had a brain block, I have a Deck object and want to get every 5 card combination from it in a iterative manner. Could someone show me how to do this, I would imagine it would be:
for(int i =0; i <52; i++){
for(int j = i + 1 ; j < 52; j++){
for(int k = j + 1; k < 52; k++{
for(int l = k + 1; l < ...
As there are 52 cards in a deck we know there are 52 choose 2 = 1326 distinct matchups, however in preflop poker this can be bucketed into 169 different hands such as AK offsuit and AK suited as whether it is A hearts K hearts or A spade K spades it makes no difference preflop. My question is, is there a nice mathematical property in whi...
Hi, I'm looking for an algorithm that given two permutations of a sequence (e.g. [2, 3, 1, 4] and [4, 1, 3, 2]) calculates the cycles that are needed to convert the first into the second (for the example, [[0, 3], [1, 2]]).
The link from mathworld says that Mathematica's ToCycle function does that, but sadly I don't have any Mathematica...
If there is an array with elements: 1,2,3,4, the program should return another array with sum of all combinations:
1
2
3
4
3 (1+2)
4 (1+3)
5 (1+4)
5 (2+3)
6 (2+4)
7 (3+4)
6 (1+2+3)
7 (1+2+4)
8 (1+3+4)
9 (2+3+4)
10 (1+2+3+4)
...
A friend of mine asked: if I have two dice and I throw both of them, what is the most frequent sum (of the two dice' numbers)?
I wrote a small script:
from random import randrange
d = dict((i, 0) for i in range(2, 13))
for i in xrange(100000):
d[randrange(1, 7) + randrange(1, 7)] += 1
print d
Which prints:
2: 2770,
3: 5547,
4:...
I was asked by somebody in an interview for web front end job, to write a function that generates all permutations of a string, such as "abc" (or consider it ['a', 'b', 'c']).
so the expected result from the function, when given ['a', 'b', 'c'], is
abc
acb
bac
bca
cab
cba
Actually in my past 20 years of career, I have never needed to...
A while back I wrote a simple python program to brute-force the single solution for the drive ya nuts puzzle.
The puzzle consists of 7 hexagons with the numbers 1-6 on them, and all pieces must be aligned so that each number is adjacent to the same number on the next piece.
The puzzle has ~1.4G non-unique possibilities: you have 7! o...
I decided to learn concurrency and wanted to find out in how many ways instructions from two different processes could overlap. The code for both processes is just a 10 iteration loop with 3 instructions performed in each iteration. I figured out the problem consisted of leaving X instructions fixed at a point and then fit the other X in...
My code has a list called INPUTS, that contains a dynamic number of lists, let's call them A, B, C, .. N. These lists contain a dynamic number of Events
I would like to call a function with each combination of Events. To illustrate with an example:
INPUTS: A(0,1,2), B(0,1), C(0,1,2,3)
I need to call my function this many times for ea...
This is not homework.
I saw this article praising Linq library and how great it is for doing combinatorics stuff, and I thought to myself: Python can do it in a more readable fashion.
After half hour of dabbing with Python I failed. Please finish where I left off. Also, do it in the most Pythonic and efficient way possible please.
fro...
This is a question on combinatorics from a non-mathematician, so please try to bear with me!
Given an array of n distinct characters, I want to generate subsets of k characters in a minimal-change order, i.e. an order in which generation i+1 contains exactly one character that was not in generation i. That's not too hard in itself. Howe...
EDIT: See http://stackoverflow.com/questions/318888/solving-who-owns-the-zebra-programmatically for a similar class of problem
There's a category of logic problem on the LSAT that goes like this:
Seven consecutive time slots for a broadcast, numbered in chronological order I through 7, will be filled by six song tapes-G, H, L, O, ...
I am trying to write a script that will take a dictionary of items, each containing properties of values from 0 - 10, and add the various elements to select which combination of items achieve the desired totals. I also need the script to do this, using only items that have the same "slot" in common.
For example:
item_list = {
'item_1...