So, i have an array of 30 elements, each of them can take the value from 0 to 1000

This part of the code is easy and i know how to write it. The complicated part is next: i need to write a program that returns the biggest value of the sum of the two adjacent elements.(a[i]+a[i+1])

For example:

a= [1,2,1,4,3]

a[0]+a[1]=3

a[1]+a[2]=3

a[2]+a[3]=5

a[3]+a[4]=7 # so it is what i'm searching for, 7 is bigger than 3, 5.

____

The thing is that i actually don't realize what methods/iterators/else? to use

.find_all doesn't seem to do what i need

.inject has the same trouble

so, what can you advice me?

thank you in advance

## 1 Replies - 2640 Views - Last Post: 29 March 2012 - 03:18 AM

### #1

# I have NO idea of how to do this task. Couldn't you hint at it?

Posted 29 March 2012 - 02:57 AM

##
**Replies To:** I have NO idea of how to do this task. Couldn't you hint at it?

### #2

## Re: I have NO idea of how to do this task. Couldn't you hint at it?

Posted 29 March 2012 - 03:18 AM

You can use the method each_cons(2) to get an enumerable containing two-element arrays for each 2 consecutive elements. So for example [1,2,3,4].each_cons(2) will give you the two-element arrays [1,2], [2,3], and [3,4]. From there you hopefully know how to continue.

Page 1 of 1