solving regular problems in scala