Monday, 29 September 2014

Entry #2 - The Folding Problem

The folding problem was quite tricky to wrap my head around. The idea of the problem is to find a way to predict the pattern of the directions of the creases on a piece of paper given the amount of times the paper was folded. I was able to get the first four patterns which gave me this result:




It occurred to me that on pattern 3, something was happening within it. Separating the pattern, I was able to see that pattern 2 and pattern 1 were in it. More importantly I noticed that pattern 2 was not only in pattern 3 twice, but the first time pattern 2 appeared, it had been flipped:

Removing pattern 1, I noticed that the other patterns followed the same format of flipping the previous pattern at the start, having a down arrow in the middle and then proceeding with the previous pattern as normal:

With this, I was able to come up with pattern 5:



With that in mind, I could very much just say that in order to predict the next pattern, start with the flipped version of the previous pattern, add a down arrow and then finish the normal version of the pattern. Looking at pattern 5 closer, I figured that there was another way to predict the patterns once I arranged it as so:



Pattern 3 is once again important to take into consideration since it outlines the patterns that follow it. The blue is the flipped version of the pink (or vice versa if it's more convenient to understand). It is then followed by a green arrow that separates the pattern. The direction in which the green arrow faces is dependent on the first pattern. 

To simplify this construct, let's create a sub-pattern which we will call a pair. One should write the blue pattern with a space and then write the pink pattern and consider it the pair. You repeat the pair 2^(x-3) times, x being the number that your pattern is. Then in order to fill in the spaces, you go to the first space on the left and then fill it in with the first arrow in the x-2 pattern. Keep doing this until both all the spaces are filled and you've finished using all the arrows in the x-2 pattern. Once that is done, the new pattern has been finished.

In summation: (U means up arrow, D means down arrow and S means space)

  • Let x be the number of the pattern (Precondition: x >= 3)
  • Let P(x) be the pattern itself (ex. P(2) = UDD)
  • Let p be a pair in which UDDSUDD
  • Repeat p 2^(x-3) times
  • Replace the first S in P(x) with the first arrow in P(x-2) and follow along until all S have been replaced and all the arrows in P(x-2) have been used
  • P(x) is completed.


Friday, 19 September 2014

Entry #1 - Understanding Logic

In the first few weeks of class, I've managed to learn new terminology and symbols that can be used when creating an implication. Such examples of that are '¬' means  the same as 'not', 'unless' means the same as 'if not', and 'necessary and sufficient' means the same as 'if and only if'. I enjoyed the examples that were given as they help me understand logic a lot better. It also helps me to create my own examples and play around with them in order to understand them. Another part that was fun was solving the street car problem since it was a different kind of problem that I've been used to seeing and by using the techniques outlined in the lectures, I was able to take an approach at it and solve the problem. I'm liking that the logic portion is intertwining with my math class since it makes the learning much more relevant to me when I see those sorts of connections come together. I don't want to say that I feel confident about the course material, but I certainly feel as though I'm doing a good job of comprehending the material and I think that I did well enough on the tutorial. Speaking of which, I feel it would be interesting to show my approach to solving one portion of the tutorial assignment.


TUTORIAL EXERCISE (WEEK 2) QUESTION 1.

GIVEN:

Three Python programs (q1.py, q2.py, q3.py) solving the same problem.

Three test suites (t1, t2, t3) that tests them.

It is known that q1.py passes all three, q2.py fails all three and q3.py fails t1 and t2 but passes t3.

PREPARATION (OR THE LET’S PART):
Let’s consider the results of the programs going through the test suites as a set like so:

program = {t1 results, t2 results, t3 results}

If the result of the test suite with the program is a pass, the element in the set will read Pass; if the result is a fail, the element will read Fail.

Let’s create set A as a constant
set A = {Pass, Pass, Pass}

Let’s say that q1.py = set B, q2.py = set C, q3.py = set D
set B = {Pass, Pass, Pass}
set C = {Fail, Fail, Fail}
set D = {Fail, Fail, Pass}

a) All three python programs pass all three test suites (FALSE)

Test q1.py: all({x in A for x in B}). It should return True because set A = set B.
Test q2.py: all({x in A for x in C}). It should return False because set A ≠ set C.
Test q3.py: all({x in A for x in D}). It should return False because set A ≠ set D.


Since set C and set D violates the conditions and we need all of them to fit the condition, the statement ∀  x ∈ {B, C, D}, x = {Pass, Pass, Pass} is FALSE. (i.e look at q2.py & q3.py)

b) Some of the three python programs pass all three test suites (TRUE)

Test q1.py: all({x in A for x in B}). It should return True because set A = set B.
Test q2.py: all({x in A for x in C}). It should return False because set A ≠ set C.
Test q3.py: all({x in A for x in D}). It should return False because set A ≠ set D.


Since set B fits the conditions and we are only looking for one or more that fits the conditions, the statement   x ∈ {B, C, D}, x = {Pass, Pass, Pass} is TRUE. (i.e look at q1.py)

c) All three python programs don’t pass all three test suites (that is, each fails at least one test suite) (FALSE)

Test q1.py: not all({x in A for x in B}). It should return False because set A = set B.
Test q2.py: not all({x in A for x in C}). It should return True because set A ≠ set C.
Test q3.py: not all({x in A for x in D}). It should return True because set A ≠ set D.


Since set B violates the conditions and we need all of them to fit the conditions, the statement  ∀  x ∈ {B, C, D}, x ≠ {Pass, Pass, Pass} is FALSE. (i.e look at q1.py)

d) Some of the three python programs don’t pass all three test suites (that is, some fail at least one test suite) (TRUE)

Test q1.py: not all({x in A for x in B}). It should return False because set A = set B.
Test q2.py: not all({x in A for x in C}). It should return True because set A ≠ set C.
Test q3.py: not all({x in A for x in D}). It should return True because set A ≠ set D.


Since set C and set D fit the conditions and we’re only looking for one or more that fits the conditions, the statement   x ∈ {B, C, D}, x ≠ {Pass, Pass, Pass} is TRUE. (i.e look at q2.py & q3.py)