dirty higher average algorithm implementation