[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie problem with modifying array correctly

Marco Guiseppe

2/8/2007 5:37:00 PM

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.cabo...

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

http://pastie.cabo...

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). :-)

--
Posted via http://www.ruby-....

2 Answers

Chris Hulan

2/8/2007 6:49:00 PM

0

On Feb 8, 12:37 pm, Marco Guiseppe <krea...@gmail.com> wrote:

> Here is an example with an array that is similar to the one my program
> will generate:
>
> http://pastie.cabo...
>
> Here is a smaller example to make it easier to understand:
>
> http://pastie.cabo...

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.cabo...

Cheers
Chris

Marco Guiseppe

2/8/2007 9:31:00 PM

0

Wow, thanks! That makes a lot of sense, now that I've spent half an hour
understanding exactly what you were doing. :-) 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.

--
Posted via http://www.ruby-....