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

Page 1 of 1

## 1 Replies - 2543 Views - Last Post: 29 March 2012 - 03:18 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=272993&amp;s=00715b9f824e1a7e878df59bd5339e52&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 tetroel

Reputation: 0
• Posts: 4
• Joined: 24-March 12

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

Posted 29 March 2012 - 02:57 AM

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?

Is This A Good Question/Topic? 0

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

### #2 sepp2k

• D.I.C Lover

Reputation: 2277
• Posts: 3,507
• Joined: 21-June 11

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