Sampling Permutations of [1,2,3,...,N] for large N
By : Hitarth Chauhan
Date : March 29 2020, 07:55 AM
this one helps. You don't need to permute at all. Call random.sample(range(52), 52) 1000 times. P.S.: You really should use zerobased indexing (range(52) as opposed to range(1, 53)) in all your work. Things generally work out better that way.

unique permutations for large sets
By : cunguyen
Date : March 29 2020, 07:55 AM
seems to work fine What you're looking for is the nary Cartesian product of a set with itself (with n = 15 over set [0, 1] in your example.) This is not the same as the #permutation lists you cite later in the question. The size of this list grows exponentially with n. For all but tiny n it would be impractical to actually materialize it. You could use a generator instead (forgive my rusty ruby): code :
class Array
def cartesian_power(n)
current = [0] * n
last = [size  1] * n
loop do
yield current.reverse.collect { i self[i] }
break if current == last
(0...n).each do index
current[index] += 1
current[index] %= size
break if current[index] > 0
end
end
end
end
>> [0, 1].cartesian_power(3) { l puts l.inspect }
[0, 0, 0]
[0, 0, 1]
[0, 1, 0]
[0, 1, 1]
[1, 0, 0]
[1, 0, 1]
[1, 1, 0]
[1, 1, 1]
=> nil
>> %w{a b c}.cartesian_power(2) { l puts l.inspect }
["a", "a"]
["a", "b"]
["a", "c"]
["b", "a"]
["b", "b"]
["b", "c"]
["c", "a"]
["c", "b"]
["c", "c"]
=> nil

Permutations Code not working Java
By : Ryan Marshall
Date : March 29 2020, 07:55 AM
seems to work fine My teacher gave me some java code and asked me to rewrite it in python. I'm not asking for help with rewriting it, but when I entered the code into my Java compiler I got this error: , There is an error in this line: code :
perm1(prefix+s.charAt(i)+s.substring(0, i)+s.substring(i+1,
N));
perm1(prefix + s.charAt(i), s.substring(0, i) + s.substring(i + 1, N));

How can I do large permutations efficiently?
By : Quadrewple
Date : March 29 2020, 07:55 AM
Does that help Your comment revealed what you're after. It's not permutations, but Cartesian product. In Python, that "translates" to [Python 3.Docs]: itertools.product(*iterables, repeat=1). code :
#!/usr/bin/env python3
import sys
from itertools import product
def filter_values(values, min_sum=0, max_sum=100, count=3):
for item in product(values, repeat=count):
if min_sum <= sum(item) <= max_sum:
yield item
def main():
weights = [float(i) / 100 for i in range(0, 105, 5)]
print("Weights: {:}\n".format(weights))
filtered_weights = list(filter_values(weights, min_sum=0.96, max_sum=1.04)) # @TODO  cfati: !!! NOTA BENE: list(...) is for display purposes only! I guess its (disastrous) effects are quite familiar when it comes to large amounts of data !!!
print("Filtering yielded {:d} elements".format(len(filtered_weights)))
if (len(filtered_weights)):
print(" First: {:}\n Last: {:}".format(filtered_weights[0], filtered_weights[1]))
if __name__ == "__main__":
print("Python {:s} on {:s}\n".format(sys.version, sys.platform))
main()
print("\nDone.")
[cfati@CFATI55100:e:\Work\Dev\StackOverflow\q056551640]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" code.py
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Weights: [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0]
Filtering yielded 231 elements
First: (0.0, 0.0, 1.0)
Last: (1.0, 0.0, 0.0)
Done.

All possible permutations for large n
By : Gourav Bhardwaj
Date : March 29 2020, 07:55 AM
seems to work fine Your goal is very likely to be impractical (how large is "large n"??? even if you can generate an enormous number of permutations, how long is it going to take you to summarize over them? How much difference in accuracy is there going to be between an exhaustive computation on a billion elements and a random sample of ten million of them?). However: The iterpc package can enumerate permutations in blocks. For example:

