The weird maths of snake folding