inversions count working in ruby