doing algorithm