Counting inversions implementation in ruby