Help with this code and its algorithm¡¡¡¡¡¡