Solving for pattern