1d algorithm stuff