Permutations that include sub-arrays in ruby?

T

Todd A. Jacobs

Ruby has a terrific implementation of single-valued permutations, but it
doesn't yield the results I expected when using arrays of arrays. For
example:

[[1, 2], [2, 3]].permutation.to_a.include? [2, 1]
=> false

The reason is that there's no permutation of the sub-arrays, just of the
top-level array elements. Am I overlooking something obvious here? I'd
like the permutations to include randomization within each sub-array,
too.
 
B

botp

The reason is that there's no permutation of the sub-arrays, just of the
top-level array elements.

you assumed that it has *only* sub-arrays

consider eg,
[[1, 2], :a, String, 3].permutation.to_a
Am I overlooking something obvious here? I'd
like the permutations to include randomization within each sub-array,

just include permutation of the sub then

kind regards -botp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top