update ruby algorithm