first version of algorithm passing first quickCheck