refactor solution by passing the parameter number