basic solving algorithm