the stock example solution - recursive way