-
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