add solve function

added solve function to code