Sunday, September 28, 2014

Week 3: This is how folding paper is very hard

We were presented with an interesting problem in this Friday's lecture:

If you continuously fold a strip of paper in half, each time folding the left end over the right end, how will the resulting sequence of up and down creases correlate with how many times it was folded?

Copious folding ensued and was recorded (reading RIGHT to LEFT):

#1 = D
#2 = D D U
#3 = D D U D D U U
#4 = D D U D D U U D D D U U D U U
#5 = we got very confused!

where the number of times the paper was folded is followed by the resulting sequence with U representing an upward crease and D representing a downward crease.

My partner and I noticed the following patterns:

- the entire sequence from the previous fold is contained in and at the beginning of the next fold
- there is some symmetry across all "middle" folds that divide their segment of the paper in half
- a lot of other details, like how creases of the next fold build on existing creases, so new creases crop up between each old crease, inspiring us to draw complicated pyramid structures with lines linking old creases down the pyramid, which turned out to be completely useless so please don't try to make sense of this sentence!

It took a third partner to pull us out of this pointless pyramid-scribbling to find a simple solution:

step 1: start with the entire sequence from the previous fold; and then add a D
step 2: "mirror" everything across the last D
step 3: replace each character from the previous step with its "opposite" character


My attempt to put this into code produces (I didn't test this a whole lot!):

public static String fold(int times)
{
if(times == 0) return "";
return sequence(times, 1, "0"); // 0 for down crease, 1 for up crease
}

private static String sequence(int times, int count, String prev)
{
if(count == times) return prev;
String mirrored = "";
for(int i = prev.length() - 1; i >= 0; i--)
{
mirrored += (Character.getNumericValue(prev.charAt(i)) + 1) % 2;
}
prev += "0" + mirrored;
return sequence(times, ++count, prev);
}

Using these methods, fold(5) returns 0010011000110110001001110011011, where 0 = D and 1 = U.

From this exercise I learned the importance of mastering the mighty computer science laziness! While I was hung up on distracting details that were clearly leading me to a complicated and wholly impractical solution, the obvious patterns were right there on the page, ready to be assembled into a very simple solution!

Monday, September 22, 2014

Week 1: Oh look, I'm blogging!

Welcome to my blog! Here I will record my experiences in CSC165, mathematical expression and reasoning, over the next few months. Hopefully you will find it interesting (haha... probably not) and it will help me process and consolidate all this new information. ADDITIONALLY (mostly), it satisfies my course requirements and I have no clue what people write in blogs!

Week 1 and 2 have gone by and I understand some material but I've imagined the rest. The lectures are very informational but occasionally a problem is introduced and I'm still musing over it while the class has moved on to another point and I've missed what a symbol or a term means and suddenly there is alien language all over the place and I'm completely lost!

∀ x ∈ E, F(x) ⇒ ¬ L(x)

Well, that's a dysfunctional funnel there with some water that will never funnel out since there's no hole at the bottom... x is an element of E! I know that one. There's also a fat arrow, one of those specialized Ikea tools, and some F(x) and L(x) that mean stuff.

The tutorial that I had in week 2, though, finally forced me to sit down and work through some of the problems. With the smaller class size, more individualized attention, and the threat of failing the quiz at the end of tutorial, suddenly everything made sense. For all x that is an element of E, F(x) returning true implies that L(x) will return false! (Right?)