naive algorithm