Canonical cut

please feel free to improve upon my code