Friday, 25 January 2013

Paper Folding Creases

In class, we had the exercise involving a strip of paper, folded left to right, in which we were required to predict the upcoming patters. My sister and I made note of a few observations when we were making a few test cases:
  • After n folds, there were 2n-1 creases.
  • The middle crease always pointed downwards.
  • If we folded again, there would be an upward crease to the left of a previous crease, and a downward crease to the right.

As such, we organized the folds into rows with the center intact, such that it looked as follows:


While trying to figure out a way to recreate this in Python code, I figured the best way to do so would be by creating a binary tree where the left child would be "U" for up, and the right child would be "D" for down:


And as such, the output would be the in-order traversal of a tree with a height of n (the number of folds). I'll post the code at some further time. I finished writing it:

To use it, simply type "paper_creases(n)", where n is the number of folds made. I'm sure this code is probably relatively inefficient, and runstyle.py would probably hate it. And just because this SLOG is called peph8:


Curses!

4 comments:

  1. I raise your fold with another fold.

    ReplyDelete
  2. Great job on finding the pattern, finding a good way to represent it (and actually implementing it)!

    ReplyDelete