solution to array-pair-sum in ruby and scala