Forum: Ruby helpppp head hurt and i m about to beat this sit up

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
614aa6cb0cc315b8ef993dea32679642?d=identicon&s=25 John Yd (abettertomorrow80)
on 2014-06-19 22:30
newarray =[]

sum  = 0
i = 0

while i < data.length
  val1 = data[i]
  j = i+1
  while j < data.length
    val2 = data[j]
    sum = val2 + val1

    newarray << val2 if sum == 0
    newarray << val1 if sum == 0

    j = j+1
  i = i+1


p newarray

#comment. the above give me the right answer which is -1 and 1...but it
doesnt give me 3 and -3...i need 3 and -3 i do that
#comment. so it stop after finding the first two numbers that add to do i make it keep going till the end of should
include 3 and -3.
8d1abb557a221370f99faf31f4953f82?d=identicon&s=25 James Red (rubyforum)
on 2014-06-19 23:14
I think you meant to have one of the 3s be positive in your data array


same code gave me this result     [-1, 1, -3, 3]
614aa6cb0cc315b8ef993dea32679642?d=identicon&s=25 John Yd (abettertomorrow80)
on 2014-06-19 23:19
thanks man lol...i slept at 3am last nite....
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2014-06-22 02:56
That's nothing dude, must of us don't sleep, just coffee coffee
This topic is locked and can not be replied to.