Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

arrays ruby and combinations

For general discussion related FlowStone

arrays ruby and combinations

Postby tester » Sat Jun 21, 2014 5:08 pm

On ruby website there is something like this:

Code: Select all
Examples:
a = [1, 2, 3, 4]
...
a.combination(2).to_a  #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
...


What I'd like to do is this.

First array to push trough combinatorics is made of numbers.
I'd like to get unique midpoints according to formula (A+B)/2.

If the array is:

100
200
300

then the output list would be something like this:

150
200
250

Second array to push through combinatorics is made of strings.
I'd like to get a list of combined strings that looks like this: A-B

If the array of string names is:

A
B
C

then the output list would be something like this:

A-B
A-C
B-C

I refer to combinatorics, because order between two arrays is important (i.e. names and their numbers).

How to make it?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: arrays ruby and combinations

Postby trogluddite » Sat Jun 21, 2014 5:52 pm

Wierd, never noticed that this one returned an 'Enumerator' instead of Array.
But handy, because '.map' can immediately follow without needing to convert to array in the middle - should be very fast!
Combinations.fsm
(600 Bytes) Downloaded 775 times

NB) If you need exact 1 to 1 correlation between index of mid-points and index of Strings, remove '.uniq' - it will remove identical values, maybe leaving the number array shorter than the String array.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: arrays ruby and combinations

Postby tester » Sat Jun 21, 2014 10:47 pm

The string array must be exact to the array of numbers. By "unique" I meant unique index combinations (i.e. to avoid Ato B and B to A). In this step - output numbers refer to midpoint descriptions. Thanks!
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: arrays ruby and combinations

Postby tester » Sun Jun 22, 2014 12:37 am

Okay, question for step 2. Similar thing as above, but now we have two separate arrays of numbers and two separate arrays of descriptors.

What I would like to do here - is to combine each element from array 1 with each element from array 2.
It would be like this

Text arrays:

A
B

C
D
E

results in

A-B
A-C
A-D
B-C
B-D
B-E

And numeric arrays go in the same way, just by the equation: x - y.

So the end result - are two synchronized arrays, one with descriptors, one with calculated data.

How to make this one?

For the rest of things (picking indexes for values in specified range), I think I have working modules somewhere around.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: arrays ruby and combinations

Postby tester » Sun Jun 22, 2014 4:08 pm

A little help here please. :-)
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: arrays ruby and combinations

Postby trogluddite » Sun Jun 22, 2014 7:52 pm

I think this is right - I'm guessing that "A-B, A-C, A-D" is a typo - should be "A-C, A-D, A-E". If not, I'm not quite sure how to make sense of the specification...
Combinations 002.fsm
(582 Bytes) Downloaded 790 times
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: arrays ruby and combinations

Postby tester » Sun Jun 22, 2014 7:59 pm

Yes, it was my mistake (long night; playing with new i-crap device since few days; the longer I have it the more I think I start do programming for them, but not because I like them - lack of apps that I would like to use...).
Thanks!
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet


Return to General

Who is online

Users browsing this forum: No registered users and 77 guests