How to use an array to solve the following...

Michael Kann mikekann at yahoo.com
Sun Feb 19 20:38:40 EST 2012


Glenn wrote:

The bigger picture will be trying to do this where there may be 3 or more
columns.

Glenn,

Please give us the "biggest" picture.

Mike





--- On Sun, 2/19/12, Glen Bojsza <gbojsza at gmail.com> wrote:

From: Glen Bojsza <gbojsza at gmail.com>
Subject: Re: How to use an array to solve the following...
To: "How to use LiveCode" <use-livecode at lists.runrev.com>
Date: Sunday, February 19, 2012, 7:09 PM

The xs values should only be "bumped" if the preceding  xs value is not the
one in sequence using 10 as the increment. No xs value (other than the very
first one or the very last one cannot have a neighboring xs value within
the increment range.

for example

xs     wt
10      6
80      7
130    23

staring with the first xs value we see that the nearest neighbor is more
than one 10 increment away so a neighbor must be added and the wt value
will always be 0 when adding a neighbor.

xs     wt
10      6
20      0  this is added
80      7
130    23

now we look at the original sequence at the next xs value (we do not start
over at the first xs value)

so the next xs value is 80 which will need a neighbor to be added on both
sides since the closest xs value on either side the lower one is  20 (yes
in comparing the nearest neighbor you need to consider new ones added) and
upper one is 130.

xs     wt
10      6
20      0  this is added
70      0  this is added
80      7
90      0   this is added
130    23

and now we look at the next xs value from the original sequence which is
130 and since it is the last value it only needs a lower neighbor to be
added since 90 is the closest one

xs     wt
10      6
20      0  this is added
70      0  this is added
80      7
90      0   this is added
120    0   this is added
130    23

This is now solved! Hopefully this makes the earlier example easier to
follow.

I am trying to avoid repeat with loops since this may make large data sets
very slow verses repeat for statements. Again, maybe with arrays this can
be done via keys?

The bigger picture will be trying to do this where there may be 3 or more
columns.




On Sun, Feb 19, 2012 at 4:20 PM, <dunbarx at aol.com> wrote:

> Glen.
>
>
> I sort of get what you are trying to do, and yes, arrays will be the most
> compact way to do it, though regular variables can work as well.
>
>
> But what happens if you already have the "xs" values in conecutive "by 10"
> order? Are you allowed to bump later values by 10? In other words, are you
> required to insert values at certain places in the list? Does this matter?
> I don't see the rationale behind where you inserted new values in your
> example. Or in yet other words, why can't new data be appended to the list,
> incremented by 10 in the "xs" portion? This is something I need to know to
> even start thinking about a method.
>
>
> Craig Newman
>
>
>
> -----Original Message-----
> From: Glen Bojsza <gbojsza at gmail.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Sent: Sun, Feb 19, 2012 1:56 pm
> Subject: How to use an array to solve the following...
>
>
> Having limited experience with arrays I thought this might be a good
> question to ask the group.
>
> Is the use of arrays to solve this appropriate? Efficient? Fast?
>
> If the answers are yes then it will help with the bigger problem that I am
> trying to address but for now I am looking for advice or help on how to do
> this using arrays... just a note the size that the solution would need to
> work on would involve a couple of hundred thousand rows.
>
> I have the following text field example with data....
>
> Pacer
> xs        wt
> 10        4
> 20        7
> 40      22
> 60      71
> 120    99
> 200    12
>
> I need to be able to ensure that between wt values that there is no more
> than 10 between xs values (this includes before and after a wt value). If
> there is then a new xs value must be added with a wt value of 0
>
> This is what the solution should look like (ignoring the <-- added
> comments).
>
> Pacer
> xs        wt
> 10        4
> 20        7
> 30        0     <---added because of wt =7 at 20 so a xs 0 value is added
> after
> 40      22
> 50        0     <---added because of wt =22 at 40 so a xs 0 value is added
> after  ***but this then solves the problem of wt 71 at 60??!!
> 60      71
> 70        0     <---added because of wt =71 at 60 so a xs 0 value is added
> after
> 110      0     <---added because of wt =99 at 120 so a xs 0 value is added
> before
> 120    99
> 130      0     <---added because of wt =99 at 120 so a xs 0 value is added
> after
> 190      0     <---added because of wt =12 at 200 so a xs 0 value is added
> before
> 200    12
>
> I look forward to comments and suggestions.
>
> regards,
>
> Glen
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list