Newbie problem with modifying array correctly

Hello,

I have an array with subarrays containing integers, and want to make
sure that the distance between any two numbers next to each other is
equal to or less than 7, also from one subarray to the next. Rigth now I
have two blocks to do this, one to check each element of a subarray
against the previous element, and one to check the last element of a
subarray against the first element in the next subarray. The problem is
that whichever block comes last mess up the work done by the first
block.

Here is an example with an array that is similar to the one my program
will generate:

http://pastie.caboo.se/38816

Here is a smaller example to make it easier to understand:

http://pastie.caboo.se/38822

If you’re not familiar with Pastie, you can click “View” on the right to
see a wrapped version (at least in Safari).

Any help is much appreciated!

PS. Using flatten is really not an option (as far as my newbie eyes can
see) because when modifying a “bad” integer I can’t just choose any
number, but need a number from the corresponding skala_rekke-subarray
(sorry about the norwegian variable-name). :slight_smile:

On Feb 8, 12:37 pm, Marco G. [email protected] wrote:

Here is an example with an array that is similar to the one my program
will generate:

http://pastie.caboo.se/38816

Here is a smaller example to make it easier to understand:

http://pastie.caboo.se/38822

HI Marco

I believe the problem is you process each row separately in the first
loop,
then go back and process the first element of each row, which in some
cases
puts in a value that doesn’t fit in the row.

I modified your example a bit, it does the first row, then for each
subsequent
row it checks the first element before doing the rest of the row.
Have a look at
http://pastie.caboo.se/38882

Cheers
Chris

Wow, thanks! That makes a lot of sense, now that I’ve spent half an hour
understanding exactly what you were doing. :slight_smile: Your help is much
appreciated, I’m learning a lot from it. It dawns on me that learning to
program is much more about logic than memorizing methods.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs