obscure algorithms related to 2d hp folding