update solution to have internally defined recursive function that is immediately invoked