New solution with patterns