Tuesday, April 2, 2013

Week 12: A week in review

So.. This will be dedicated to a critique on my progress... and oh hey look the existence of other people.

I've spent almost two hours reviewing other classmates' slogs, all I have to ask is how do you and the professor manage?

For the 165 weekly quizzes, I am beginning to get stuck on proofs involving big- theta when there are multiple variables and functions being compared those involving the proof of a limit which I need to review because I've somehow forgotten it... These, I can only improve on through practice with past tests. I keep doubting myself when I answer a question, then record a second attempt that is usually wrong when I approach these problems. Practice makes perfect.

I could have posted on other people's slogs a lot more, it's really interesting to see how other people think and go about in approaching a problem to learn different techniques. Uh so to be honest I kinda of regret not talking enough in my tutorial classes to ask people for help and questions.
Either its the gender gap-
       *been there done that in high school...(Let's just say I know way more than I need to know)
       *This year...
       *goes to first CSC148 lab
       *looks beyond monitor
       * sees person staring with dumbstruck face*(twitches)
- or I'm being lazy or shy I don't know, but I need to overcome that dumb barrier otherwise I'll just be wasting a lot of good opportunities in the future -____- and this joy-ride is just beginning...
 
I have stuck with two close friends in particular to do the assignments with and I'm beginning to only see more and more why I need to put myself out there a bit more. Learning from others is key, because the days without their help will come sooner or later, and I'll suffer if I keep relying on them of course, especially as a girl, I need to get used to the gender gap (and find a way of how to survive) that has only increased even further than as compared to my high school CS courses.
By doing group work, I realize I'm horrible at trying to figure out what I'm confused and I have some difficulty figuring out a way to form a question for it O_O. I think I know it, but I don't, but then again, this just pushes for the need to talk with other peers a lot more to problem solve. Looking at the student slogs and Piazza would have been a good place to start, because it's easier to get away with, asking for feedback in a slightly anonymous way. Out of all of the slogs, there were a few that appealed to me for their different aspects.

http://forcsc165.wordpress.com/
This person's slog is pretty informative, in terms of the way they relate the 165 class concepts to a few of their other courses to programming languages and compilers. They have well structured attempts to solving the in class problems like the diagonal problem. Their posts are straight and to the point unlike mine which include ranting. If I knew this person I would have learned quite a bit from this person if I knew them in person aside from 165 content, judging by the connections they make to other CS-related topics- especially those of their A2 post.

http://exp-csc165.blogspot.ca/
Dannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnngg

Well ok A+ to this person for their slog LOL. Well if not from the professor, then an A+ from me, despite the fact that my grade aren't sufficient enough to send over those percentages.
This person's slog is filled with problem solving techniques, I'm sorry I have no interest in the chess section of their blog, but everything else on here has a very detailed approach on how they solve their problems. This person's posts aren't too bland either so it keeps you reading for more on answers and little tips to look for in surviving 165, hah they even mentioned the Project Euler page, which is a pretty good resource with those familiar  familiar 50000003204893242378493278 programming problems to solve and ponder about. The slog is a worthwhile read.

Now to sum it up after reflecting on what I could have done in this course to improve, I wonder what it'll be like taking CSC 236 next year...

Problem Solving: Paper Folding

Understand the problem:
Predict the sequence of up and down folds for any number of times you fold a strip of paper in half



Devise a Plan
  1. Hypothesize what pattern will occur in the sequence of folds produced for each folding         operation made.
  2. Observe and record the folding operation, folding the paper in half from 1 to 5 times, then record the number of 'half-folds' and their up and down pattern of creases produced in an organized  table.
  3. Look for a pattern betweens between each sequence of up(U) and down(D) creases made    from each folding operation carried out and compare them with previous sequences made before the current fold operation. Note down and verify your conjectures with real results and simulations from your observation table in Step 2.
  4. Create and test an algorithm on how you can predict the sequences produced from executing a number of n folding operations.
  5. Simulate the folding operation in a Python program.


Carry out the plan

1.
 HypothesizeBecause the creases of previous folding operations are permanently embedded on the strip of paper, the next sequence will depend on the sequence of the previous folding operations. This hints to the fact that the folding operation is recursive. The next result depends on the previous results that ultimately depend on the first result, the smallest, simplest instance of this folding operation, the base case. When the folding operation is carried out once a single downward crease is made.


2. Observe and record
By making multiple folds, we can produce the following table of upward(U) and downward(D) creases occurring in each fold sequence.



3. Look for a pattern
Looking at the table, we can see that the first fold reappears in all sequences produced after      
the first folding operation. The 'D' fold can be found in the very middle of each sequence.


If the first downward fold recurs throughout all sequences, then there should be more
 reappearing patterns. Lets look for them...



The sequence from making n = 1 folds, DDU reappears. Also, notice how when we fold for          
more the strip of paper more than once, part of the fold sequence before the first D produced          
when n = 1, is reflected on the paper strip to the right of the first D crease, in a reversed  
pattern. The D made from when n = 1 acts as a 'mirror' in which everything to the left of 
is reversed in folds, going from D -> U or U -> D, producing a 'reflection' on the right side of
mirror D. 

D recurs through all sequences. Our hypothesis is true.

In our example, the sequence DDU for n = 2 reappears in all other sequences for n > 2.
DDUDDUU, the sequence of n = 3 reappears in sequences for which n > 3...
The same thing occurs for the sequence n = 4, n = 5 and so forth.

Now what importance does this have?

Parts of the folding sequences enclosed in the same coloured rectangles are identical patterns that repeat from the previous n-1 before it.


we can see that...




4. Create and test an algorithm

- our simplest case of the folding operation is when n, the number of half-folds made on the strip of paper, is n = 1, the sequence produced is D

- Notice that the 'left pattern' to the left of the mirror D (produced from n = 1) is D, which is reflected(D changes to U), producing the 'right pattern' to the right of the mirror, U.
But, where do we get the left pattern from?
The entire previous sequence becomes the new left pattern.

Knowing these facts, we can create a rough idea that:

- resulting fold sequence =         left pattern           +       D       +          right pattern
                                       previous sequence           mirror          reflection of left pattern

Testing...
If this is so, knowing that when n = 2, a sequence of DDU is produced.
Then, for n = 3:
     - the left sequence should be DDU, the previous sequence in its entirety,
     - the mirror is D as always
     - the right sequence, generated by 'reflecting' the left sequence is: UUD
     - when 'reflecting' a sequence, you reverse the pattern sequence and change U or D's to their  
       opposites**
So the final fold sequence for n = 3 is: DDUDUUD
Checking our observation table, this pattern generated is correct.


Testing our formula to produce a sequence for n = 3 will match without error if true.

Given n = 3 produces a sequence DDUDUUD,

Then for n = 4, the sequence should be:
DDUDUUDDUDDUDUU,
which matches the real results according to the observation table.

Then, for n = 5, the fold sequence should be DDUDUUDDUDDUDUUDDDUDUUDUUDDUDUU,
which is correct.


5. Simulate

We can create pseudo code from this summary to structure the Python program for this problem:
=======================================================================
Pseudocode
fold_sequence(number of half-folds):
      sequence = ''
      mirror = D
      if number of half-folds == 1:
            sequence = D
      if number of half folds > 1:
            sequence += previous fold sequence + mirror + reflection of previous fold                      
                      #      ^                                               sequence
                      # recursive call here
      return sequence

reflect(fold sequence):
''' Some helper method to 'reflect' fold sequences.'''
    reflection = ''
    for every character in fold sequence:
        if character is D:
            add U to reflection
        else:

            vice versa of above
        reverse reflection
return reflection

=======================================================================Python Code

DOWN = 'D'
UP = 'U'
MIRROR = 'D'

def gen_fold_sequence(n):
    ''' (int) -> str
    Return the sequence of upward(U) and downward(D) creases given the number
    of half-folds.
    '''
    sequence = ''
    if n == 1:
        sequence += MIRROR
    elif n > 1:
        left_pattern = gen_fold_sequence(n-1)
        sequence += gen_fold_sequence(n-1) + MIRROR + reflect(left_pattern)
    return sequence

def reflect(s):
    ''' (str) -> str
    Return a reflection given s, the sequence.
    '''
    reflection = ''
    if len(s) >= 1:
        for char in s:
            if char == UP:
                reflection += DOWN
            else:
                reflection += UP
    return reflection[::-1]

if __name__ == '__main__':
    for i in range(1, 6, 1):
        print(gen_fold_sequence(i))