Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. 1 class Person
  2. 2 attr_accessor :name
  3. 3 def test(a)
  4. 4 min = 0
  5. 5 max = a.count()-1
  6. 6 puts max
  7. 7 puts "****"
  8. 8 a.each_with_index do |el, idx|
  9. 9 array = el
  10. 10 arrayMin = a[0,idx]
  11. 11 arrayMinSum = arrayMin.inject(:+)
  12. 12 arrayMax = a[idx+1, max]
  13. 13 arrayMaxSum = arrayMax.inject(:+)
  14. 14 if arrayMinSum == arrayMaxSum
  15. 15 puts a[idx]
  16. 16 end
  17. 17 sleep 1
  18. 18 end
  19. 19 end
  20. 20 end
  21. 21
  22. 22 puts " "
  23. 23
  24. 24 person = Person.new
  25. 25 a = [-1,3,-4,5,1,-6,2,1]
  26. 26
  27. 27 person.test(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement