Thursday, January 31, 2013

Problem Solving: Folding

This post covers the "Folding" problem as done in class for one dimension, plus a bit of what I did on my own. If I have time, I will hopefully follow with a post that solves the problem for two dimensions.

The problem asks for the sequence of ups and downs in creases given that one folds a strip of paper in a particular way. Our initial plan was to simply fold it a couple of times and record the pattern. (We had a plan B, which was actually thinking about how/why the folds actually were the way they were mathematically, but it made more sense to start with examples).

This was done with a chart that looked something like this:

fold pattern
1
2 ∧ ∨ ∨
3 ∧ ∧ ∨ ∨ ∧ ∨ ∨
4 ∧ ∧ ∨ ∧ ∧ ∨ ∨ ∨ ∧ ∧ ∨ ∨ ∧ ∨ ∨

There seemed to be a pattern, but we did not quite grasp it until a light bulb suddenly lit up over my head and I re-recorded the folds so they aligned with folds from previous folds, so something like this:

fold pattern
1
2
3
4
∧∧∨∧∧∨∨∨∧∧∨∨∧∨∨

It became apparent that each time we folded the paper, it was inserting an up-down repeating pattern between the old folds. We all understood the pattern pretty well, but we could not figure out a mathematical way to describe it in class.

I later came up with a block of python code that works for the first three folds:

def folding(fold):
    '''(int) -> (list of str)
    return pattern of folds'''
    L = []
    i = 0
    while i <= (2**fold - 2):
        if i % 2 == 0:
            if i % 4 == 0:
                L.append('up')
            elif i % 4 == 2:
                L.append('down')
        elif i % 2 == 1:
            if i % 4 == 1:
                if i % 8 == 1:
                    L.append('up')
                elif i % 8 == 5:
                    L.append('down')
            elif i % 4 == 3:
                L.append('down')
        i += 1
    return L


Unfortunately, this only works up to fold 3. For it to work for more folds, it would be necessary to either write a ridiculous amount of code... or use recursion. Which I simply do not know how to do very well yet. However, at least for the first three folds:
folding(3)
['up', 'up', 'down', 'down', 'up', 'down', 'down']
folding(2)
['up', 'up', 'down']
folding(1)
['up']

If I have time to return to this problem, I will actually write python code that gives an actual solution, as well as tackle the two-dimensional version of this problem in part II. 

Tuesday, January 22, 2013

And Implies Or

Last week was mostly spent continuing to represent English statements in logical symbols, so, for example, A^B => AvB, as A and B is a subset of A or B.

However, A^B is clearly not the same thing as AvB. So, applying that, when the sign outside MP103 says "NO FOOD AND DRINKS", clearly they meant that I can have a can of coke or a yummy sandwich, just not both together. (Which is probably why some kind individual surreptitiously scratched out the "AND" and replaced it with "OR", which is probably what the original author intended.)

I am under the impression that so far, by covering the differences between 'and' and 'implies', we're secretly being introduced to truth tables (which are more clear about the difference, in my humble opinion) without a lot of the technical mumbo-jumbo that tends to make students' brains go haywire and shut down in panicked self-defense.

However, that did not stop one brave student's outcry at various counter-intuitive but logical claims, which was by far the most entertaining part of that particular lecture. 

Monday, January 14, 2013

Quantifiers: four different representations

The first three classes of CSC165 saw the introduction of two key quantifiers (universal and existential), at first disguised as python code, then in the context of a word problem, illustrated with Venn diagrams and finally in terse mathematical symbols.

It was most fun to figure out on my own how each statement relating to the scenario of employees/salary (a scenario that raised social issues, questioned gender inequality in the workplace, and included a thoroughly mysterious woman with a yearly salary of $500), and I found it interesting to find all the different ways of representing a single English statement. "All employees make over 9000$", for example, can be written as python code, in math with sets/subsets or union/intersections, and illustrated by a Venn diagram.

My biggest problem remains the fact that I am not actually yet enrolled in the class.Thus far, I have found the class very manageable, and the topics well-explained and easy to understand. It also helps that I happen to be extremely fond of Venn diagrams.