small algoritmic exercise