-
as seen on Stack Overflow
- Search for 'Stack Overflow'
I have n elements. For the sake of an example, let's say, 7 elements, 1234567. I know there are 7! = 5040 permutations possible of these 7 elements.
I want a fast algorithm comprising two functions:
f(number) maps a number between 0 and 5039 to a unique permutation, and
f'(permutation) maps the…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
Hello!
I want to do permutation in perl. For example I have three arrays. ["big", "tiny", "small"] and then I have ["red", "yellow", "green"] and also ["apple", "pear", "banana"].
How do I get:
["big", "red", "apple"]
["big", "red", "pear"]
..etc..
["small", "green", "banana"]
I understand this…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
Continuing to learn prolog, I'm trying to write a permutation(L1, L2) predicate. It should return true, only if L1 can be made up of all elements in L2. My code so far is the following:
permutation([], []).
permutation([H|T], L2) :- remove(L2, H, R), permutation(T, R).
Assuming that the predicate…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
Let say a=[A, B, C, D], each element has a weight w, and is set to 1 if selected, 0 if otherwise. I'd like to generate permutation in the below order
1,1,1,1
1,1,1,0
1,1,0,1
1,1,0,0
1,0,1,1
1,0,1,0
1,0,0,1
1,0,0,0
Let's w=[1,2,3,4] for item A,B,C,D ... and max_weight = 4. For each permutation…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
I'm interested making an implementation of the 14-15 puzzle:
I'm creating an array with the values 0 - 15 in increasing order:
S = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
Now, what I want to do is shuffle them to create a new instance of the puzzle. However, I know that if I…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
I'm looking for an algorithm in c# that solves a combinatorics problem:
Assume i have the objects 1,2,3,4
I want to get all possible ways to group these object in multiple groups, that each time contain all objects. Order is not important. Example:
<1,2,3,4
<1,2 / 3,4
<1,3 / 2,4
<1…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
I am trying to solve a combinatorics problem, it seems easy, but i am having some trouble with it.
If i have at most X tables, and N persons to sit on the tables, Each table can have 1 to N seating places, and I can only sit persons in one side of a rectangular table( so the order how people sit…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
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…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
This is not a 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…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
This is not a 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…
>>> More