Grasshopper

generative modeling for Rhino

# Jitter component without repetiton of branches?

Hi,

I am trying to apply a permutation to a set of values and obtain, as output, all of the possible arrangements without any duplicate.

As an example

if I have the following set of 3 values:

﻿﻿﻿{A,B,C}   n=3

I want to obtain:

{A,B,C}; {A,C,B}; {C,A,B}; {B,C,A}; {B,A,C}; {C,B,A}

I know that the possible arrangements will be given by n! (see *)

that means 3! = 3x2x1 = 6

I will have 6 possible arrangements.

So, I tried using the Jitter component with 6 different seeds values but I obtain a set of values with some kind of repetition (B,C,A is missing and C,B,A is repeated twice). Why is this happening? Is it wrong to use the jitter component with different seed values?

Many thanks!

kiara

*(or n!/(n-k)! if the size k of the permutation needs to be different from the number n of values in the set)

Views: 541

### Replies to This Discussion

With only 3 variables I don't think you are going to see the variance in such a finite amount of seeds.

I would use this approach:

Still using the Jitter component, but with overkill in generating the sequences. Then you can use (with a bit of string manipulation) the Create Sets component to get your unique versions.

Attachments:

great! thanks Danny for the quick reply!

I had increased the seed number but couldn't figure out how to delete the duplicate branches...was stuck with numbers and didn't think of manipulating the strings. Just perfect!

thanks,

kiara

This sounds like a job for Bicycle Repair Man.

This will be quite tricky to achieve, especially if you have a large set of initial values, as you will most likely end up generating a lot of combinations, then reducing the collection using Set components (as Danny pointed out).

I mocked up another approach, though I don't think this is what you're after either as it generates values that contain a certain value twice (AAB). Plus it only works on single characters.

I think you may have to venture into scripting to get this one right with a minimum of wasted processor cycles and memory.

--

David Rutten

david@mcneel.com

Attachments:

I added the Substring component at the end so it can work on multiple characters.

Both suggestions are very useful in order to choose whether we want either "n!" solutions (6 arrangements without repition of any value) or "n power of n" solutions (27 arrangements considering repitition of values).

many thanks!

kiara

the attachment
Attachments:

I am working on something similar with numbers where I am trying to find all possible summations of 5 numbers without "duplicates".  for example:

(If I used three numbers instead for simplicity) 1, 5, 6 would be 1,5,6,6,7,11,12

In this case the two 6's are not actually duplicates bc one is 6+none of the other numbers and the other is 5+1, yet 1+5 would be a duplicate since those numbers had been added already.

Is there a simple way of finding these values for a set of 5 values?

In the ABC definition above, repeated solutions with a different letter orders would count as a distinct solutions but with numbers the order wouldn't matter. I'm not sure if I am over thinking this and making this a more difficult problem than it is?  Any advice?

Here's a method that needs a Binary sequence to work.

for example:

000 = (0*6)+(0*5)+(0*1) = 0

001 = (0*6)+(0*5)+(1*1) = 1

010 = (0*6)+(1*5)+(0*1) = 5

011 = (0*6)+(1*5)+(1*1) = 6

100 = (1*6)+(0*5)+(0*1) = 6

101 = (1*6)+(0*5)+(1*1) = 7

110 = (1*6)+(1*5)+(0*1) = 11

111 = (1*6)+(1*5)+(1*1) = 12

Attachments:

very cool danny, i just do not get it how the cluster works. I oen it and treid to understand, but I didin´t.

Best Regards

Dedackel

To convert a decimal number to binary you divide it by 2 and keep going until you get to zero making a note of the remainder as you go.

157 \ 2 = 78 remainder 1

78 \ 2 = 39 remainder 0

39 \ 2 = 19 remainder 1

19 \ 2 = 9 remainder 1

9 \ 2 = 4 remainder 1

4 \ 2 = 2 remainder 0

2 \ 2 = 1 remainder 0

1 \ 2 = 0 remainder 1 <--- Left hand number 10011101

And thats why it is limited to 8 numbers.

I think I got it.

Thanks Danny!