and arrays again

For general discussion related FlowStone
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

and arrays again

Post by tester »

Let say that there are two arrays:

1
2
3
4

a
b
c
d

And I'd like to get:

1 - a
2 - b
3 - c
4 - d

So it wold mean two inputs for two arrays, and custom separator " - " for formatting. How to make it in ruby? How to avoid an error, if two arrays are different in size?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: and arrays again

Post by billv »

This ones been fun tying to work out as well tester. A bit tricky though.
I did a version that works great, accounts for errors, but is string output,
not array like you need...but In the meantime, still might help... :mrgreen:
Tester array_single output version.fsm
(2.55 KiB) Downloaded 1056 times


I can see how the array output can be done...fun challenge.... :D
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: and arrays again

Post by RJHollins »

Question?

Is the '-' anything more than formatting ? If not, you show a 2D array that would then be 'the' data ... and for display purposes you could handle alignment, spacing, '-', etc, all from GUI control [even PRIMS].

Just trying to understand the need.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: and arrays again

Post by Nubeat7 »

@tester:

Code: Select all

@c= []
0.upto @a.length-1 do |i|
   @c[i] = (@a[i].to_s)+"-"+(@b[i].to_s)
end
output @c


but you need to fix the arrays before with trogs fix_array_size methode
Last edited by Nubeat7 on Sun Nov 03, 2013 1:31 am, edited 1 time in total.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: and arrays again

Post by billv »

look at testers post again...his needs are very clear...

at the moment , tying to map em both together via loop....
EDIT:
Just saw your post..
Thanks nubeat..will have a go...
strangeChild
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: and arrays again

Post by strangeChild »

Green is not dead...
If it wasn't for the white-space these few primitives would do the trick nicely.
Attachments
closeNoCigar.fsm
(407 Bytes) Downloaded 1044 times
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: and arrays again

Post by trogluddite »

tester wrote:How to make it in ruby? How to avoid an error, if two arrays are different in size?

Depends which you prefer...
- Default value adding to the "short" array.
- Take away surplus from the "long" array.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: and arrays again

Post by billv »

This was as far as i got..

Code: Select all

def event i,v

if i == 0 then

x = 0
data = Array.new
for i in 1..@a1.length do
data[x] = i = @a1.map.to_s{|x| x}+("-")+ @a2.map.to_s{|x| x}
x += 1
output 0,data
end

end
end

...and result...

Code: Select all

#<Enumerator:0x3abce3c>-#<Enumerator:0x3abcd60>
#<Enumerator:0x3abccac>-#<Enumerator:0x3abcb80>
#<Enumerator:0x3abcb30>-#<Enumerator:0x3abcae0>
#<Enumerator:0x3abca90>-#<Enumerator:0x3abca18>
#<Enumerator:0x3abc978>-#<Enumerator:0x3abc8d8>

:lol: ..

strangeChild wrote:Green is not dead...

nice circuit...
Thanks for the reminder of how much i miss working in green... :)
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: and arrays again

Post by tester »

In greenery I'm doing it like this (see attachement).

I prefer to recalculate the "pool" each time it changes. I could generate one larger, once - and use "string array split", I'm aware of that, but I would have to remember about that limitation too. I'm using this one, because it's easier to adapt, depending on where it is used, and it has no limitation (less to remember - less to worry about). On the other hand - it's slower, or it adds some slowdowns when it's among others.

Now - if the pool is dynamic in size, large, formatting changes "on-the-fly" per click for some reason (don't ask me "why" - that's the part of my movie, where I'm predicting "possible scenarios"), and it's clicked often, then this one adds it's own slowdown to the whole project.

It is used for combinig display and for saving. Not for loading (in terms of processing), because items have associated indexes used separately.

*

So my original question was regarding general simplification. Combine array1 and array2, and place between them a mark with whitespaces (these are a nghtmare sometimes). Add mark with witespaces always after array1, and always before array2, while array1 and array2 may have different amounts of elements.

*

I know I'm doing it in reversed order, but just wanted to post some example. Now I will read and check what you wrote above. :)
Attachments
greenery.fsm
(552 Bytes) Downloaded 1053 times
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: and arrays again

Post by tester »

Nubeat7 wrote:@tester:

Code: Select all

@c= []
0.upto @a.length-1 do |i|
   @c[i] = (@a[i].to_s)+"-"+(@b[i].to_s)
end
output @c


but you need to fix the arrays before with trogs fix_array_size methode


This one works reasonably fine, thanks. First array defines formatting and output size, second is just added and trimmed if it's larger. Actually this trimming might be useful too. White spaces are simply to add (" - " works).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Post Reply