Weirdly: adv. In a strikingly odd or unusual manner
The Latest - Pick One

16-07-2014 Points on a Parabola

You can try it out here with this JavaScript version of the code. A modern-ish browser required, as it uses an HTML5 canvas.

A couple of years ago, I wrote a simple program in C that lets you drag three different points around on the screen. These points would be used to calculate a parabola that they all lie on, and plot that parabola on the screen. The algebra used in working out the function for the parabola is relatively easy to do, and that is the subject of this blog.

As you may recall, a parabola can be represented using a quadratic equation:

y = ax2 + bx + c

The work then is pretty straightforward. We'll take the x and y coordinates of any three points (where no two have the same x value), and plug each pair of values into the equation above. With each of them we can solve for either a, b or c. Once we have any of those three terms calculated, we'll substitute it into one of our other solutions, eliminating that variable. Repeating this process will eliminate all three of them, defining them strictly in terms of our three given points.

The points in this case will be defined as (x1, y1),(x2, y2). and (x3, y3). We'll start with the simplest one, solving for c:

y1 = ax12 + bx1 + c
c = y1 - ax12 - bx1

Next we'll solve for b, by using (x2, y2) for our x and y values, while replacing c with the equation above

y2 = ax22 + bx2 + c
y2 = ax22 + bx2 + (y1 - ax12 - bx1)
bx2 - bx1 = y2 - ax22 + ax12 - y1
b (x2 - x1) = y2 - a(x22 - x12) - y1
b (x2 - x1) = y2 - y1 - a(x2 - x1)(x2 + x1)
b =
y2 - y1
x2 - x1
- a(x2 + x1)

Now we have a solution for c given b and a, and a solution for b given a. Next we'll find our solution for a, and put the whole thing together.

y3 = ax32 + bx3 + c
y3 = ax32 + bx3 + (y1 - ax12 - bx1)
y3 = ax32 - ax12 + bx3 - bx1 + y1
a(x32 - x12) + b(x3 - x1) = y3 - y1
a(x3 - x1)(x3 + x1) + b(x3 - x1) = y3 - y1
a(x3 + x1) + b =
y3 - y1
x3 - x1
a(x3 + x1) +
y2 - y1
x2 - x1
- a(x2 + x1)
=
y3 - y1
x3 - x1
a(x3 + x1 - x2 - x1) =
y3 - y1
x3 - x1
-
y2 - y1
x2 - x1
a(x3 - x2) =
(y3 - y1)(x2 - x1) - (y2 - y1)(x3 - x1)
(x3 - x1)(x2 - x1)
a =
(y3 - y1)(x2 - x1) - (y2 - y1)(x3 - x1)
(x3 - x1)(x2 - x1)(x3 - x2)
a =
x2y3 - x1y3 - x2y1 + x1y1 - x3y2 + x1y2 + x3y1 - x1y1
x32x2 - x3x22 - x32x1 + x1x2x3 - x1x2x3 + x1x22 + x12x3 - x12x2
a =
y1(x3 - x2) + y2(x1 - x3) + y3(x2 - x1)
x12(x3 - x2) + x22(x1 - x3) + x32(x2 - x1)

And now we have our three coefficients, and can use our original quadratic equation to calculate the y co-ordinate of any point on the curve given its x co-ordinate.

06-11-2013 A Better Ellipse

I have been bothered by a particular equation for a very long time. It is the commonly provided equation for an ellipse, and is usually defined as follows:

(x - x1)2
a
+
(y - y1)2
b
= 1

Where the center of the ellipse is located at the point (x1, y1), with its x radius equal to a and its y radius equal to b. This is all well and good as far as it goes; my dislike for it lies in the fact that the only ellipses it can be used for are those with a length that is parallel to either the x or y axis of the graph. If you want to plot one that lies on a different angle, then this will not work.

There is however another way to define an ellipse that is not subject to that restriction. It can be done using the relationship between an ellipse's border and its focal points:

The sum of the distances between the focal points of an ellipse and any point on its border is a fixed constant.

This means that if we take any two points - we'll call them (a, b) and (c, d), and set a fixed value for the sum of the two line segments' length (we'll call that e), then we can define any ellipse as follows:

√[(x - a)2 + (y - b)2] + √[(x - c)2 + (y - d)2] = e

That in itself is fairly simple. The real difficulty is in solving that equation for y, giving us a usable function to work with. This is a problem that I have tried on and off many times throughout the years, and inevitably failed. The trouble isn't in the math itself, but in the sheer volume of it. To solve this, all you need to do is get rid of the radicals by separating and squaring them, then expand the equation out to simple terms, regroup them, and then factor "y" out of the resulting equation. To get rid of the radicals though, you have to square some terms repeatedly, giving you a significant quantity of terms to manage.

I've probably tried to solve that about a dozen times over the years, and always gave up when doing the expansion. I finally cracked it this week when switching from working on paper to working on the computer. I initially expected it to add to the work, but found that once I got used to it, that wasn't the case. It also became much easier to re-check and make corrections, and having an infinite canvas to work on is great.

So after several more failed attempts over the past two weeks, I'm very happy to present this solution worked out from the basic equation given above.

We can begin with removing the radicals by separating and squaring them:

√[(x - a)2 + (y - b)2] + √[(x - c)2 + (y - d)2] = e

√[(x - a)2 + (y - b)2] = e - √[(x - c)2 + (y - d)2]

(x - a)2 + (y - b)2 = e2 - 2 e √[(x - c)2 + (y - d)2] + (x - c)2 + (y - d)2

(x - a)2 + (y - b)2 - e2 - (x - c)2 - (y - d)2 = - 2 e √[(x - c)2 + (y - d)2]

[(x - a)2 + (y - b)2 - e2 - (x - c)2 - (y - d)2]2 = 4 e2[(x - c)2 + (y - d)2]

With all of the radicals removed, we now expand.

( + x2 - 2 a x + a2 + y2 - 2 b y + b2 - e2 - x2 + 2 c x - c2 - y2 + 2 y d - d2 )2 = 4 e2 (x - c)2 - 4 e2 (y - d)2

( - 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 y d - d2 )2 = 4 e2 (x2 - 2 c x + c2) - 4 e2 (y2 - 2 d y + d2)

- 2 a x (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
+ a2 (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
- 2 b y (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
+ b2 (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
- e2 (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
+ 2 c x (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
- c2 (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
+ 2 y d (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
- d2 (- 2 a x + a2 - 2 b y + b2 - e2 + 2 c x - c2 + 2 d y - d2)
= 4 e2 (x2 - 2 c x + c2) + 4 e2 (y2 - 2 d y + d2)

+ 4 a2 x2 - 2 a3 x + 4 a b x y - 2 a b2 x + 2 a e2 x - 4 a c x2 + 2 a c2 x - 4 a d x y + 2 a d2 x
+ 4 a b x y - 2 a2 b y + 4 b2 y^y - 2 b3 y + 2 b e2 y - 4 b c x y + 2 b c2 y - 4 b d y2 + 2 b d2 y
- 4 a c x2 + 2 a2 c x - 4 b c x y + 2 b2 c x - 2 c e2 x + 4 c2 x2 - 2 c3 x + 4 c d x y - 2 c d2 x
- 4 a d x y + 2 a2 d y - 4 b d y2 + 2 b2 d y - 2 d e2 y + 4 c d x y - 2 c2 d y + 4 d2 y2 - 2 d3 y
- 2 a3 x + a4 - 2 a2 b y + a2 b2 - a2 e2 + 2 a2 c x - a2 c2 + 2 a2 d y - a2 d2
- 2 a b2 x + a2 b2 - 2 b3 y + b4 - b2 e2 + 2 b2 c x - b2 c2 + 2 b2 d y - b2 d2
+ 2 a c2 x - a2 c2 + 2 b c2 y - b2 c2 + c2 e2 - 2 c3 x + c4 - 2 c2 d y + c2 d2
+ 2 a d2 x - a2 d2 + 2 b d2 y - b2 d2 + d2 e2 - 2 c d2 x + c2 d2 - 2 d3 y + d4
+ 2 a e2 x - a2 e2 + 2 b e2 y - b2 e2 + e4 - 2 c e2 x + c2 e2 - 2 d e2 y + d2 e2
= 4 e2 x2 - 8 c e2 x + 4 c2 e2 + 4 e2 y2 - 8 d e2 y + 4 d2 e2

Now we can simplify by grouping like terms, factoring, etc. and separate y from the rest of the equation.

+ 4 a2 x2 - 8 a c x2 + 4 c2 x2 - 4 e2 x2
+ 4 b2 y2 - 8 b d y2 + 4 d2 y2 - 4 e2 y2
+ 4 a2 c x - 4 a3 x - 4 a b2 x + 4 a c2 x + 4 a d2 x + 4 a e2 x + 4 b2 c x - 4 c3 x - 4 c d2 x + 4 c e2 x
- 4 a2 b y + 4 a2 d y + 4 b2 d y - 4 b3 y + 4 b c2 y + 4 b d2 y + 4 b e2 y - 4 c2 d y - 4 d3 y + 4 d e2 y
+ 8 a b x y - 8 a d x y - 8 b c x y + 8 c d x y
+ a4 + b4 + c4 + d4 + e4 + 2 a2 b2 - 2 a2 c2 - 2 a2 d2 - 2 a2 e2 - 2 b2 c2 - 2 b2 d2 - 2 b2 e2 + 2 c2 d2 + 2 c2 e2 + 2 d2 e2
- 4 c2 e2 - 4 d2 e2
= 0

+ 4 x2 (a2 - 2 a c + c2 - e2)
+ 4 y2 (b2 - 2 b d + d2 - e2)
+ 4 x(a2 c - a3 - a b2 + a c2 + a d2 + a e2 + b2 c - c3 - c d2 + c e2)
- 4 y(a2 b - a2 d - b2 d + b3 - b c2 - b d2 - b e2 + c2 d + d3 - d e2)
+ 8 x y (a b - a d - b c + c d)
+ (a2 + b2 - c2 - d2 - e2)2
- 4 e2 ( c2 + d2)
= 0

+ 4 x2 ((a - c)2 - e2)
+ 4 y2 ((b - d)2 - e2)
+ 4 x((c - a) (a2 + b2 - c2 - d2 ) + e2 (a + c))
- 4 y((b - d) (a2 + b2 - c2 - d2 ) - e2 (b + d))
+ 8 x y (a - c)(b - d)
+ (a2 + b2 - c2 - d2 - e2)2 - 4 e2 ( c2 + d2)
= 0

+ 4 x2 ((a - c)2 - e2)
+ 4 y2 ((b - d)2 - e2)
+ 4 x((c - a) (a2 + b2 - c2 - d2 ) + e2 (a + c))
- 4 y((b - d) (a2 + b2 - c2 - d2 ) - e2 (b + d) - 2 x (a - c)(b - d))
+ (a2 + b2 - c2 - d2 - e2)2 - 4 e2 ( c2 + d2)
= 0

+ 4 x2 ((a - c)2 - e2)
+ 4 y2 ((b - d)2 - e2)
+ 4 x((c - a) (a2 + b2 - c2 - d2) + e2 (a + c))
- 4 y((b - d) (a2 + b2 - c2 - d2 - 2 x (a - c)) - e2 (b + d))
+ (a2 + b2 - c2 - d2 - e2)2 - 4 e2 ( c2 + d2)
= 0

We now have y separated in such a way that we can solve it as a quadratic equation, which we can do as follows:

Let:
u ≡ 4 ((b - d)2 - e2)
v ≡ - 4 ((b - d) (a2 + b2 - c2 - d2 - 2 x (a - c)) - e2 (b + d))
w ≡ 4 x2 ((a - c)2 - e2) + 4 x((c - a) (a2 + b2 - c2 - d2) + e2 (a + c)) + (a2 + b2 - c2 - d2 - e2)2 - 4 e2 ( c2 + d2)

Then:
u y2 + v y + w = 0

And so:
y =
-v ± √(v2 - 4 u w)

2 u


y =
4
(b - d)
a2 + b2 - c2 - d2
- 2 x (a - c)
- e2 (b + d)
±
 
  -4
(b - d)
a2 + b2 - c2 - d2
- 2 x (a - c)
- e2 (b + d)
 
2
- 4 [4 ((b - d)2 - e2)]
4 x2 ((a - c)2 - e2)
+ 4 x((c - a) (a2 + b2 - c2 - d2) + e2 (a + c))
+ (a2 + b2 - c2 - d2 - e2)2
- 4 e2 ( c2 + d2)
 
1/2

2 [4 ((b - d)2 - e2)]


y =
4
(b - d)
a2 + b2 - c2 - d2
- 2 x (a - c)
- e2 (b + d)
±
  16
(b - d)
a2 + b2 - c2 - d2
- 2 x (a - c)
- e2 (b + d)
2
- 16 ((b - d)2 - e2)
4 x2 ((a - c)2 - e2)
+ 4 x((c - a) (a2 + b2 - c2 - d2) + e2 (a + c))
+ (a2 + b2 - c2 - d2 - e2)2
- 4 e2 ( c2 + d2)
 
1/2

8 ((b - d)2 - e2)


y =
(b - d)
a2 + b2 - c2 - d2
- 2 x (a - c)
- e2 (b + d)
±
 
(b - d)
a2 + b2 - c2 - d2
- 2 x (a - c)
- e2 (b + d)
2
- ((b - d)2 - e2)
4 x2 ((a - c)2 - e2)
+ 4 x((c - a) (a2 + b2 - c2 - d2) + e2 (a + c))
+ (a2 + b2 - c2 - d2 - e2)2
- 4 e2 ( c2 + d2)
 
1/2

2 ((b - d)2 - e2)

Depending on your browser, that final equation may be somewhat difficult to read (thank-you underdeveloped HTML math notation). In lieu of that, here is the same final result as an image:
ellipse equation

I'm quite happy with this, but still need to work out an equation of similar complexity. What I ultimately want to do with this is to create a C function that can draw an ellipse given the focal points and the total distance ("e" in the solution above). In order to do that effectively, I'll need to know the minimum and maximum x values of the ellipse. One way to get this would be to take the contents of the radical, set them as being equal to zero, and solve for x. That then is my next objective; hopefully there will be an update soon.

13-03-2012 Stacked Domes

Recently, when administering a bath for my one-year-old daughter, I came across an interesting question that turns out to be a somewhat tricky one to answer.

The question arises when playing with a particular bath toy. This toy (shown on the right) is a set of ridged semi-spherical domes (or rather, hemispheres), that nest within each other. The nearest ones in size can be snapped together to form a ball of sorts (one side slightly smaller than the other). Also, they can be stacked on top of each other, with smaller ones snapping on to the outside of larger ones to form a roughly conical shape.

Another feature of this toy is that each of the domes has a hole in the top with a diameter of approximately one inch. When a smaller dome is placed on top of a larger one, an open chamber is formed between them. If air then passes through them rapidly (as happens when they're dropped open-side-down into the water), the passing air creates a whistling sound. This whistling sound changes pitch depending on which combination of domes are snapped together, presumably due to the volume of the air trapped between them - the larger chamber allows a lower pitch.

It's this interaction of the pieces that brings to mind the question that we'll explore here. What combination of these domes will give us the lowest possible pitch? Or rather, if we have a hemisphere resting with its flat side down, and place a smaller hollow hemisphere on top of it, trapping space between them, what radius in the smaller hemisphere will allow the greatest possible volume contained between the two shapes?

We know that the top hemisphere can't have a radius of zero, or the volume contained would be zero as well. Also, it can't be exactly that of the larger hemisphere, or they would stack neatly together, again giving us a contained volume of zero. Between those two extremes lies the number we're looking for.

To solve this, we'll need to take the volume contained by the smaller hemisphere at any given radius, and subtract the amount that overlaps with the larger one. We can then take the derivative of that equation and solve it for zero, which should give us the point at which the volume is greatest.

For the sake of this problem, we'll say that the larger hemisphere (which we'll call h1) has a radius of 1. The smaller hemisphere (we'll call that one h2), is the one whose radius we're calculating, so we'll refer to that as r. The volume of a hemisphere is of course half that of a sphere, giving us v = 2/3πr3. The more challenging part is to find the volume of the segment of h2 that overlaps with h1 (referred to as a "spherical cap").

The usual equation for the volume of a spherical cap is πh(3a2 + h2) / 6 where h is the height of the cap, and a is the radius of its base. That base radius will in fact be the radius of our smaller hemisphere, r, so we can rewrite that to say: πh(3r2 + h2) / 6
and subtract it from our hemisphere volume for h2:
v = 2/3πr3 - πh(3r2 + h2) / 6
giving us a basic equation for the volume of our contained space.

The next thing we need to do is eliminate the variable h, which is the height of the cap that lies within h2. We can actually work that out pretty easily, as shown in the diagram on the right. We know that h1 has a radius of 1, and that h2 has a radius we call r. That gives us two sides of a right triangle, the long side being the radius of h2 and the hypotenuse the radius of h1. We can use those with the Pythagorean theorem to calculate the third edge of that triangle, which represents the distance between the bottom center points of h1 and h2. That distance is (1 - r2)½. We know that the remainder of h1's radius lies within h2, and that h1 has a radius of one, so we can say that the height of the cap we're looking for is 1 - (1 - r2)½.

Now we can modify our volume equation, replacing h with its relationship to r:
∵ v = 2/3πr3 - πh(3r2 + h2) / 6
∵ h = 1 - (1 - r2)½
∴ v = 2/3πr3 - π(1 - [1 - r2]½)(3r2 + [1 - (1 - r2)½]2) / 6
∴ v = 2/3πr3 - π(1 - [1 - r2]½)(3r2 + 1 - 2[1 - r2]½ + 1 - r2) / 6
∴ v = 2/3πr3 - π/6(1 - [1 - r2]½)(2r2 + 2 - 2[1 - r2]½)
∴ v = 2/3πr3 - π/3(1 - [1 - r2]½)(r2 + 1 - [1 - r2]½)
∴ v = 2/3πr3 - π/3(r2 + 1 - [1 - r2]½ - r2[1 - r2]½ - [1 - r2]½ + 1 - r2)
∴ v = 2/3πr3 - π/3(2 - 2[1 - r2]½ - r2[1 - r2]½)
∴ v = 2/3πr3 - /3 + /3(1 - r2)½ + π/3r2(1 - r2)½

Next we'll take its derivative:
dv/dr = 2πr2 + π/3(1 - r2)(-2r) + /3r(1 - r2)½ + π/3r2 ⋅ ½(1 - r2) ⋅ (-2r)
dv/dr = 2πr2 - 2πr / 3(1 - r2)½ + 2πr(1 - r2)½ / 3 - 2πr3 / 6(1 - r2)½

and let dv/dr equal zero, solving for r:
0 = 2πr2 - 2πr / 3(1 - r2)½ + 2πr(1 - r2)½ / 3 - 2πr3 / 6(1 - r2)½
∴ 0[3(1 - r2)½ / 2πr] = [2πr2 - 2πr / 3(1 - r2)½ + 2πr(1 - r2)½ / 3 - 2πr3 / 6(1 - r2)½][3(1 - r2)½ / 2πr]
∴ 0 = 3r(1 - r2)½ - 1 + (1 - r2) - r2/2
∴ 0 = 3r(1 - r2)½ - 3r2/2
∴ 0 = (1 - r2)½ - r/2
r/2 = (1 - r2)½
r2/4 = 1 - r2
5r2/4 = 1
∴ r2 = 4/5
∴ r = 2 / √5
∴ r = 2√5 / 5

Leaving us with our final answer. To contain the maximum amount of space between two stacked hemispheres, the one on top should be 2√5/5, or approximately 0.8944272 times the size of the one it sits on.

28-08-2011 Fun with logic gates

When I was in college, I took a rather enjoyable math course that was taught by a professor named Gerry Dworschak. He's the teacher who gave us the rather puzzling bonus problem that I've previously blogged about, the falling stick.

One of the subjects that was covered in that course was boolean algebra, and on the final exam, the last question was the following:

prove that (A ⊕ B) ⊕ (B ⊕ C) = A ⊕ C

The most intuitive way to do it is to simply say that the B's cancel each other out, giving you the end result in one step. The parentheses prevent it from being that simple though, so the problem needs to be done a little more carefully. One way to solve it is to simply expand the exclusive ors and reduce the expression to its simplest terms. That's what I did at that point:

(A ⊕ B) ⊕ (B ⊕ C)
= (AB' + A'B) ⊕ (BC' + B'C)
= (AB' + A'B)(BC' + B'C)' + (AB' + A'B)'(BC' + B'C)
= (AB' + A'B)(BC')'(B'C)' + (AB')'(A'B)'(BC' + B'C)
= (AB' + A'B)(B' + C)(B + C') + (A' + B)(A + B')(BC' + B'C)
= (AB' + A'B)(B'B + B'C' + CB + CC') + (A'A + A'B' + AB + BB')(BC' + B'C)
= (AB' + A'B)(B'C' + CB) + (A'B' + AB)(BC' + B'C)
= (AB'B'C' + AB'CB + A'BB'C' + A'BCB) + (A'B'BC' + A'B'B'C + ABBC' + BAB'C)
= (AB'C' + A'BC) + (A'B'C + ABC')
= AB'C' + A'BC + A'B'C + ABC'
= B(A'C + AC') + B'(AC' + A'C)
= (B + B')(AC' + A'C)
= A'C + AC'
= A ⊕ C

And clearly that method works. Last night however, I was looking for something to do and decided to revisit this question. In doing so, I came up with a much more elegant solution. Instead of expanding and simplifying the above problem, simply prove that the Associative property holds true for an exclusive or operator. Then the brackets can simply be removed, and the B's cancel each other out. So here's how I did it:

Prove that (A ⊕ B) ⊕ C ≡ A ⊕ (B ⊕ C)
(A ⊕ B) ⊕ C   A ⊕ (B ⊕ C)
(A'B + AB')'C + (A'B + AB')C'   A'(B'C + BC') + A(B'C + BC')'
((A'B)'(AB')')C + A'BC' + AB'C'   A'B'C + A'BC' + A((B'C)'(BC')')
(A + B')(A' + B)C + A'BC' + AB'C'   A'B'C + A'BC' + A(B + C')(B' + C)
(AA' + AB + A'B' + BB')C + A'BC' + AB'C'   A'B'C + A'BC' + A(BB' + BC + B'C' + CC')
(AB + A'B')C + A'BC' + AB'C'   A'B'C + A'BC' + A(BC + B'C')
ABC + A'B'C + A'BC' + AB'C'   A'B'C + A'BC' + ABC + AB'C'
ABC + A'B'C + A'BC' + AB'C'   ABC + A'B'C + A'BC' + AB'C'
q.e.d.

With that proven, we can now say:

(A ⊕ B) ⊕ (B ⊕ C) ≡ A ⊕ (B ⊕ B) ⊕ C
= A ⊕ (∅) ⊕ C
= A ⊕ C

11-07-2010 Another good math puzzle

I saw another good little math puzzle today, and enjoyed it so much I thought I'd share it.

This came from a question on Wiki Answers, which I was glad to be able to answer. The question is:

Can you guarantee that in any set of five numbers, you can always find a set of three whose sum is divisible by three?
The answer to which is yes, and we can demonstrate that by disproving the opposite. In other words, we can show that it's impossible to create a set of five numbers in which there is no combination of three whose sum is divisible by three.

The first thing we need to do is think of our possible numbers as members of different sets. These sets will be whole numbers that are three apart from each other. There are exactly three such sets, and they are:

  1. a(x) = 3x + 0 = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, ...}
  2. b(x) = 3x + 1 = {1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, ...}
  3. c(x) = 3x + 2 = {2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, ...}
You will see that these sets cover all of our whole numbers, and therefore the entire range of numbers that we can pick from for this problem

There are two important behaviors to note about these sets:

  1. If you take any three numbers out of any one of those sets, they will always add up to make a multiple of three. We can show this pretty easily. Let's start with our first set, a(). Because all members in that set are multiples of three, we know that all possible sums of that set will always be a multiple of three as well. In other words, 3x + 3y + 3z + ... will always be equal to 3(x + y + z + ...), and therefore, always divisible by three.

    The second set, b(), is not quite as obvious, but also pretty simple. Let's make an equation for the sum of any three numbers of that set. We'll call their indicies x, y, and z. Their sum then can be expressed as:

    • b(x) + b(y) + b(z)
    • = (3x + 1) + (3y + 1) + (3z + 1)
    • = 3x + 3y + 3z + 3
    • = 3(x + y + z + 1)
    Because the result is divisible by three - regardless of what x, y and z are, we know that this will be true for the sum of any three numbers in that set.

    This is also true for the third set, c():

    • c(x) + c(y) + c(z)
    • = (3x + 2) + (3y + 2) + (3z + 2)
    • = 3x + 3y + 3z + 6
    • = 3(x + y + z + 2)
    Again giving us that factor of three. This means that for our original conditions to be met, we can't have more than two numbers out of any one of those sets.

  2. If you take one number out of each of the three sets, and add them together, those too will also add up to a multiple of three. This can again be proven using the same method:

    • a(x) + b(y) + c(z)
    • = (3x + 0) + (3y + 1) + (3z + 2)
    • = 3x + 3y + 3z + 3
    • = 3(x + y + z + 1)
    This tells us that in order for our conditions to be met, we can't have a number from each of those three sets. In other words, We can only have numbers from two of our three sets.

Since we can only pick from two of the three sets, and can only pick two from each set, this means that the most numbers we can before meeting this condition is four. Which means the answer to our original question is yes.

24-04-2010 Ponx!

Just a quick post to share my latest creation, Ponx! I whipped this together last night and this morning. It's just another version of Pong. Nothing special about it (although I'm pleased with the graphics), but it was a fun little number to whip together.

I actually started this with the intention of having two clients connect to the server, and play games against each other via AJAX calls to the server. I realized though that the time required to grab/pass information through the server was too long to be able to handle a live action game. A turn-based game, or one that's not critically dependent on timing, would do well though, and I'll be looking at doing something along those lines soon.

In the mean time, feel free to send me feedback at .

30-12-2009 Solving Quadratic Equations

When we're in high school, one of the equations we're told to memorize is the one for solving quadratic formulas. The rule we're taught is:

if:

then:

And this is indeed true. Sadly, what many of us are not taught (and I count myself in that unfortunate group), is why that is the case. As described in my earlier blog about the volume of a sphere, it was always a frustration of mine simply being told to memorize these things without being given a real understanding of how they work. To remedy that, I gave myself a quick mental exercise this evening, trying to reach the latter equation given the former one. It turned out much easier than I thought, and here's a breakdown of how it works.

We'll start by converting the left hand of the equation into a perfect square, a technique called "completing the square"

Those last two steps are the key to this solution. By multiplying both sides of the equation by "a", we turn the first term into a perfect square. By adding (b/2)2 to both sides, we create a term who's square root is equal to half of "b". This makes the left side of our equation a perfect square, allowing us to reduce to a single term with the variable x:

It's a really great feeling to be able to find the explanation and understand it without looking it up.

14-11-2009 Tricks for Testing Divisibility

There are several useful tricks that are often taught in grade school for checking the divisibility of numbers. These vary in complexity, the reason for their working ranging from the very obvious to the very obscure.

Basically...

The base in which we express numbers is a key part of the work explored here. It is important then to understand what we mean by a numeric base. This is quite often and quite incorrectly thought of by people as weird, complicated stuff; I have heard countless comments of not "getting" it. It is in fact fairly elementary math that almost everyone already understands the background of. In fact, there are no new tricks or concepts to learn. The only mathematical ideas that are needed are among those taught to us in grade school: additon, multiplication, and exponents.

Consider the way we express a number. Let's take my birth year, nineteen-seventy-six. we normally express that as:

1976

Now consider the individual digits in that number, 1, 9, 7 and 6. As we're all taught in our earliest years, those digits each fall into a column, often referred to as "ones", "tens", "hundreds", etc. We call them that because the digit in that column does not actually represent its own value, but a multiple of its own value. When we look at this number, we don't think of it as being simply "1 + 9 + 7 + 6". Instead, we see that it means "1000 + 900 + 70 + 6". That can also be expresed as:

1×1000 + 9×100 + 7×10 + 6×1

or:

1×103 + 9×102 + 7×101 + 6×100

In other words, each column represents a power of ten that is multiplied by the number in that column. Those powers increment with each column from right to left.

Other numeric bases work exactly the same way. The only difference between them is the base, ie. the number that those exponents are applied to. Normally that base is ten because we have ten unique symbols that represent the first ten values, 0 through 9. There is nothing preventing us from using other numbers though. For example, computers use binary, or "base two" numbers. These work exactly the same way as decimal, but instead of having ten unique symbols, it only has two, "0" and "1". As a result, the columns used in expressing the numbers are not powers of ten, but powers of two. Instead of ones, tens, hundreds, etc. the columns in a binary number are ones, twos, fours, eights and so on. So the same number we used above, rather than being expressed as "1976", would instead be:

11110111000

If you break it down and convert it back to decimal, it comes out like this:

1×210 + 1×29 + 1×28 + 1×27 + 0×26 + 1×25 + 1×24 + 1×23 + 0×22 + 0×21 + 0×20

or:

1024 + 512 + 256 + 128 + 0 + 32 + 16 + 8 + 0 + 0 + 0
= 1976

This same technique of expressing numbers works in any numeric base. For example, in "hexadecimal", or base 16, we would use 16 unique symbols, rather than 10. The standard there is to use letters as additional symbols, so the digits in use would be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. That same number would then be expressed as "7B8", or:

7×102 + B×101 + 8×100

which, if we convert back to decimal, would be:

7×162 + 11×161 + 8×160
= 7 × 256 + 11 × 16 + 8 × 1
= 1792 + 176 + 8
= 1976

Some time ago, a friend and I were discussing the reason behind a method for testing whether or not a number is divisibile by three. In figuring out the logic of it, I developed a bit of a curiosity for these techniques, and the application of them in other numeric bases. The purpose of this writing is to explore some of the commonly known ones, and rewrite them in a way that can be applied in any base (see sidenote).

To start out, let's take a look at some of the most common tricks for checking the divisibility of a number. A number is divisible by:

Many of these methods can be grouped together in more generic terms, because they follow similar rules. For example, 2 and 5 work in the same way, as do 3 and 9. It is a generic version of each of these rules that we will explore here.

Numbers ending with 0's

Starting with the simplest one then. If the last digit of a number is a 0, then that number is divisible by ten. This is because of the way our notation works. For each ten numbers we count, we reset the first column to 0, and increment the next column by one. This applies to any numeric base, and always for the number represented by the symbols "10". In binary then, the last digit being a 0 means the number is divisible by two. In hexidecimal, that closing zero means it's divisible by 16. More exactly then, a number is divisible by the base in which it's expressed if the last digit of the number is a 0.

That can of course be expanded upon to include divisibility by 100, 1000 and so on. One might say that an integer can always be divided by the base in which it's written, raised to the power of as many 0's as there are on the right end of that integer. This statement holds true even if there are no zeros at the end of the number. In that case, we're saying that the number is divisible by 100, which equals one.

Factors of the base we're working in

The next simplest trick is the one we apply to both division by 2 and division by 5. At first glance, those two may seem to work differently, but they are in fact identical. Each of those tricks works because the number we're dividing by is a factor of the base we're working in. This is why it only applies to 2 and 5 when we're working in regular decimal arithmetic; those are the only two factors of ten.

Because they're factors of ten, when we count multiples of these numbers, the "ones" column in our number will always be a multiple of these numbers. Consider keeping a tally, starting at 0 and incrementing it by 5. You would get the values 5, 10, 15, 20, 25, and so on. You can see that the rightmost digit gets reset to zero each time our tally hits a multiple of ten. Because 5 is a factor of 10, our tally will hit every multiple of ten. As a result of that, the rightmost column will always be a value that is a multiple of this number which is less than 10. That applies equally to multiples of 2, only we're dealing with a larger set of multiples. Instead of 0 and 5, we have 0, 2, 4, 6 and 8.

This same rule can be applied in any other base as long as the base is not a prime number. A good example of this would be base 12 notation. Because 12 has more factors than 10, we can apply it more broadly. In base 12:

We can say then that if X is a factor of the base we're working in, then a number is divisible by X if its last digit is a multiple of X.

Divisibility of a limited set of digits

This is a trick that is commonly applied to check for multiples of 4 and 8. If the rightmost two digits form a number that is divisible by 4, then the number itself is as well. Similarly, if the last three digits are divisible by 8, then the entire number is. This is in fact a slightly more complicated version of the same method we use to check for divisibility by 5 and 2.

It works with the number 4 because in decimal, the number that we express as "100" is divisible by 4. This means that the last two digits will go through a limited set of combinations (25 specifically), before they get reset to 00. The other effect of this is that the same last pair of digits will be used no matter what combination of remaining digits is in place. As a result of this, we can see if 4 is a factor of a number simply by seeing if 4 is a factor of its last two digits.

The same technique works with the number 8. The only difference here being that 8 is not a factor of 100 (ie. 102), but of 1000 (103). Because of this, we have to check the last three digits instead of the last two.

This can of course be applied in other numeric bases as well. One such example would be in base 12 notation when checking multiples of 8 or 9. This works because 8 and 9 are both factors of 122, but not of 12 itself.

To formally state this trick then, we can say that where B is the base in which a number is expressed, if BP is divisible by X, then X will be a factor of any number whose last P digits are divisible by X.

Counting the sum of the digits

This is a technique that we use for multiples of 9 and 3. To check (in regular decimal notation) whether a number is divisible by three, simply add its digits together. If the sum of those digits is divisible by three, then the number itself is. This is applied to multiples of 9 in the same way. If the sum of the digits is divisible by 9, then the number itself is too.

One neat aspect of this is that you can apply it recursively. For example, to see if 4897284 is divisible by three, just add its digits: 4 + 8 + 9 + 7 + 2 + 8 + 4 = 42. Still not sure? then simply add those digits: 4 + 2 = 6. Six is divisible by 3, so you know that 42 is as well, and therefore 4897284 is also.

The reason this works is rather interesting, and I have actually explained it in depth in an earlier blog. Here though is a short answer:

This happens because the number we're testing for has a multiple that is exactly 1 less than the base we're working in. This is easiest to see when working with multiples of 9. Looking at those, you get 9, 18, 27, 36, 45, 54, 63, 72, and so on. It is important to note that each time the "tens" column is increased by 1, the "ones" column is decreased by 1. This means that the two columns will always balance each other out. It is the fact that 9 is one less than the base we're using that allows this to happen.

This also applies to other bases as well. For example, in hexadecimal (base 16), this would apply to the numbers 3, 5, and E. Take the multiples of 5 for example: 5, A, E 14, 19, 1D, 23, 28, and so on. In each one of these, if you add the digits, they add up to a number that is a multiple of 5.

In other words, if X has a multiple that is one less than the base a number is expressed in, then a number is only divisible by X if its digits add up to a value that is itself divisible by X

Subtraction Tricks

Divisibility by 7 is one of the less commonly used and more awkward to understand tricks. using this method, we take one part of the number, and subtract a multiple of it from the other part of the number. In the case of divisibility by 7, we can take the "ones" column, multiply it by two, and subtract it from the rest of the number. If the resulting difference is divisible by seven, then the original number is as well. That pattern can be repeated on the resulting number until we get down to 7, -7, or 0.

For example, take the number 9268. We'll take the last digit, "8", double it, and subtract from the first three, "926". 926 - (2 × 8) = 910. Not sure? Repeat the process. 91 - (2 × 0) = 91, and 9 - (2 × 1) = 7. Seven is of course divisible by seven, so we know then that 9268 is as well.

This works because of a relationship between the digits, and a particular multiple of 7. First, consider our original number, 9268. We'll break that down into the two numbers we're working with, 926 and 8. Let's take two variables, A and B. we'll say that A equals 926 and B equals 8. In that case we can say:

9268 = 10A + B

In that case, if 9268 is divisible by 7, then 10A + B is as well. With that in mind we can say that if 10A + B is divisible by 7, then 20A + 2B is as well. All we're doing here is doubling the original number, so seven remains a factor.

At this point, we know that 20A + 2B has a factor of 7, but we don't know if either A or B does. We do however know that 21A would have a factor of 7, no matter what the value of A is. We know this because 7 is a factor of 21. With that in mind, we can say:

if 20A + 2B is divisible by 7, then 20A + 2B - 21A is also divisible by 7.

and then we can simplify it:

20A + 2B - 21A = -A + 2B

Whether the number is positive or negative does not affect its divisibility, so we can easily say that if -A + 2B is divisible by 7, then A - 2B is also. Recall that B is our rightmost digit, and A is the rest of the number. This is how this method of testing works.

We can apply this trick in other bases as well. An example of this would be for testing multiples of 5 in base 8 (octal) notation. Take the decimal number 190. In octal, this would be expressed as 276. The trick to divide by 5 in octal would be to take the last digit, "6" in this case, multiply it by three, and subtract it from the remainder of the number. We would have:

27 - 3×6 = 27 - 22 = 5

That may look wrong at first glance but remember that's octal notation, not decimal. If we expressed that statement in decimal, it would read "23 - 3×6 = 23 - 18 = 5".

This method can be used generically to define tricks for any number of factors. It works best for those that have a small multiple that is one away from a multiple of the base in which the number is expressed. Another example of this, in our more familiar decimal notation, would be in checking for multiples of 13. Using the same method, we can say that if a number is divisible by 13, then we can represent its rightmost digit with "B", and the remaining digits with "A", and say:

10A + B is divisible by 13
∴ 40A + 4B is divisible by 13
∴ 40A + 4B -39A is divisible by 13 (as 39 is also a multiple of 13)
∴ A + 4B is divisible by 13

So we can take the last digit of a number, quadruple it, and add it to the rest of the number. If the result is divisible by 13, then the rest of the number is as well. Having to multiply by 4 rather than 2 makes this a somewhat less convenient trick, but nonetheless a working one. For example, take the number 16042:

1604 + (2 × 4) = 1604 + 8 = 1612
161 + (2 × 4) = 161 + 8 = 169
16 + (9 × 4) = 16 + 36 = 52
5 + (2 × 4) = 5 + 8 = 13
Combinations of tricks

These tricks can also be combined. Division by six is an excellent examlpe of that. If the number's digits add up to a multiple of three, and if it's an even number, then the number is a multiple of six. This works of course because 2 and 3 are both factors of 6. A similar combination in hexadecimal would be testing for multiples of ten (or "A"). A number is divisible by A if it's an even number, and if its digits add up to a multiple of 5. This is because 2 and 5 are the two factors of A.

In Summary

In closing then, here is a summary of the tests outlined above, re-expressed in a way that can be applied in any numeric base.

If:

Then:

  1. X is divisible by Bn, where n is the number of 0's on the end of X
  2. if B is divisible by F, then X is divisible by F if the last digit of X is a multiple of F
  3. if Bn is divisible by F, then X is divisible by F if the last n digits of X form a multiple of F
  4. if F has a multiple that is one less than B, then X is divisible by F if the sum of the digits in X is divisible by F

You may notice that the second statement here is actually a subset of the third one. That is, if B is divisible by F, then Bn is as well. The only difference here is that in the first case, n can be as low as "1". I keep them separate because of the unique distinction of F actually being a factor of B, as opposed to simply sharing a common one.

11-06-2009 Number Puzzle

In playing around with numbers today, I came up with a nice little brain teaser. After alpha-testing it on a friend I thought I'd post it here for the world's perusal.

The number 71352 is a multiple of 3. Without the use of a pencil, paper, calculator, etc. take that same set of digits, and rearrange them in such a way that they form another multiple of 3.

Click here to see the answer.

08-01-2009 Updates

I'm afraid I've been very out of touch lately as far as this blog is concerned, and quite a few noteworthy things have happened and gone sadly unreported.

Firstly and most important, Celeste and I are now engaged! Needless to say, this thrills me to bits. I know this will sound like the ravings of a man madly in love (which I most certainly am), but we really are a match made in whatever blissful location one's deity allows.

On a far less thrilling note, the other big news is that I am once again on the job hunt. Layoffs being as little fun as they are though, I have to say I'm once again finding myself surprisingly unbothered by it. I think there are two key reasons for this. First, Celeste keeps my morale quite high just being the all-around awesome person that she is. Also, I miss living in Ottawa. Don't get me wrong on this point - London's actually a nice town, and less expensive to live in. It's just that Ottawa is home-turf for both of us, and most of the people we know live in and around there.

That being said, I'm not at all against moving somewhere else or even staying here if the right opportunity shows up. I am looking primarily on Ottawa and Montreal though. If you know any good leads (or happen to be a potential employer), please do drop me a line!

The only other "update" I have is that of my origami page, www.diagrami.com. It has recieved a very significant overhaul and a complete re-write of the back end. The layout and design of the page was done by Celeste, who has both a natural talent and work experience in the field. The back-end coding is my own work. The big change on the back-end is that it no longer queries the data from a MySQL database. This was becoming cumbersome as the database was stored on a separate machine from the page itself. Instead, I wrote some PHP functions that generate AWK commands to extract the data from local text files. This has the advantages of not only being faster, but also far more portable and with more malleable data.

21-06-2008-Bad Drivers

WARNING: Pissed Off Cyclist WARNING: This blog was written while very irate. Vulgarities ahoy!

I've said on multiple occasions that there are a lot of bad drivers on the road who who lack the mental capacity to understand that cyclists belong there too. For a long time, I've had a gem of a story that exemplifies the stupidity of bad drivers.

It was about five years ago when I was driving down one of the busier streets of Ottawa (Walkley Road). I was in the right lane, and keeping to the right side of it, when an idiot pulled up in a rusty bucket on wheels and yelled out, "get your act together and drive on the sidewalk". The sheer stupidity of that line would make most people wonder if this guy had the brain power to spell "IQ", but he conclusively answered that about 30 seconds later. At that point, we were approaching an intersection, him ahead of me. He was turning right and I was going straight through, so as is required by law, I took the rightmost straight through lane (the one to his left). At that point, he stopped his car, blocking the turning lane, and got out to pick a fight. I almost wish his passenger hadn't pulled him back into the car, as I was in much better shape than he was.

As of today however, I now have a better example of bad drivers - and all around bad people - on the road. Last night I was riding around the streets of London Ontario, minding my own business, when a wax paper cup full of pop and ice went flying past my head. At that point some retarded teenagers in their daddy's SUV went flying past me hooting something.

Now, normally, for those of you who don't know me, I'm a very passive, live-and-let-live kind of guy. In this case though, I was pissed off. I was god damned royally "rip their fucking ears off and shove 'em up their asses" pissed off. Lucky for me (or perhaps unlucky, depending on your take on the matter), they pulled up to a red light after flying by, so I was able to pull up in the right lane - directly beside them.

At that point, I looked at the pipsqueak of a pimple factory in the passenger seat (the culprit who threw the cup), welled up a big-ass hork of booger, and spat in his face. It wasn't just a little ball of saliva either. It was a nice big digusting spray all over the front seats. I'm fairly certain I got all three of the little fuckers.

In retrospect, this is where I make a mistake. I took off on my bicyle at that point. I should instead have stayed exactly where I was, and waited for the little soap-bar-hole-fuckers to do something about it. I did take off though, and that was where the chase began. I very quickly hung a right on to the intersecting street, with another car coming up close, forcing the brats to stay one car back. I took up the whole lane to ensure that buffer stayed there, and then hung a fast right on to another street after a stop sign. By the time those lame-ass fuckers got around the corner I was about thirty metres ahead of them. I then took a sharp right as they gunned to catch up with me, forcing them to slam the breaks and squeal their tires around the bend.

At this point, it was a longish straight street with no near exit. They were maybe twenty metres behind me when they squealed around the corner, so I decided to slow down, letting them catch up. Once they were about five metres back, I sharply swerved into a driveway on the right, dodging another projectile that they threw out the passenger window. I then turned around and went in the opposite direction. I could see they were maybe two hundred metres down the street and turning around as I took a right around the bend.

I then took the next right turn, and was down at the other end of the block when I saw them turn on to it after me. Then, after two lefts, and another right, I could see them gunning the engine to catch up again, maybe thirty metres back. Ahead of me though, the road was closed for construction, and only the left turn ahead was available. I got within a few metres of that intersection when they caught up again, hurling several items out the window. They missed me for the most part though (with the exception of a minor bump against my elbow), and at that point I was able to loose them by hopping up on the sidewalk of that closed street - going where they could not.

And that was the end of my big adventure yesterday. I do believe though, with my 20/20 hind vision, I should have done things differently. As I said before, the chase could have been avoided altogether if I had simply spat in the little fucker's eye, and waited for him to step out of the vehicle. Or perhaps after that pursuit, I should have tried to get their license plate number, and spoken to the police. That being said, I think I'll just start carrying a bat, and if I ever meet those little fuckers again...

03-06-2008 Life is Wonderful

Happy Jacob (C) 2008, Celeste Agnes

Life is treating my very well at the moment, and I have an itch to tell the world that I feel fantastic! This is largely due to the fact that I have got the BEST GIRLFRIEND IN THE UNIVERSE!!! I'd love to list off all of her wonderful traits, but then the Internet would be full and I wouldn't even be halfway done. This picture of me that she doodled very nicely captures exactly how I feel though.

And as if that weren't enough joy (which it most certainly is), I also just started working at the job I've always wanted - writing computer games. All in all life is fantastic, and if I had a mountaintop to sing from, I'd be yodeling at the top of my lungs.

Just wanted to share the joy.

06-05-2008 U-Haul Sucks

Having just recently landed myself an awesome job that has the one drawback of being 600km away, I'm preparing to move to a new city. One of the great "joys" of moving is the acquisition of a vehicle that is large enough to port all of your worldly goods across significant tracts of land. This is a quick review of just how terrible "U-Haul" is, and why you should never bring them your business.

u-suck van

I've made the mistake of using their service before. Two and a half years ago, I moved in to the apartment that I am now preparing to leave. It should have been a quick and simple move, as I had everything packed and ready, and was only moving about eight kilometres.

I started by going to the "U-Haul" web site, where they give you a convenient online form to reserve the truck you need when you need it. Thinking that was just dandy, I went ahead and made just such a reservation. Being somewhat anxious though, and wanting to cover all my bases, I also called the phone number they provided, to confirm that the reservation was indeed successfully placed. I was assured that yes, a truck would be ready for me and I could go pick it up at 08h00 on the morning move.

Fast-forward a couple of weeks to the time of my move. I was all set. One friend, who would be driving the truck for me, joined me first thing in the morning and we went to pick up the truck I had reserved. When we got to the local "U-Haul" outlet, there was already a long and very slow moving queue of people waiting to be served at their desk. After waiting in line for over an hour, we finally got to the desk where we were told that no trucks were available. When I mentioned that I had a reservation, the lady behind the desk explained that such reservations don't actually get reported to the local office, and so they could not honour it. The best they could do is have a truck ready for me after another customer returns it that afternoon.

Disgruntled but without any other options, we went back to my old place and waited for the arrival of other people who would be joining. Once everyone arrived, we went out and grabbed lunch at a local restaraunt, killing time until the truck could be acquired. Unfortunately, some of the people who were there to help were only available in the early afternoon, as I was expecting to be finished the move by then. As a result, by the time we could go back to pick up the truck (going through the same lineup and even more waiting after that), the only assistance some of them could offer was in loading the truck. The unloading would be handled by myself and two others, one of whom was - although an awesome person - not the most muscular in the world and hence not able to do the heavy lifting.

In the end, a move for which I was well prepared on my end, which should have taken only two or three hours, wound up consuming the entire day. We returned the truck to their after-hours drop-off, late in the evening.

Now fast-forward to the present day. Once again I am preparing to move. Having more or less learned from "U-Haul"'s mistakes, I had already sworn that I would never again bring them my business. Being a bit of a penny pincher though, I thought I'd take a look at their prices to compare with the companies I'd checked out so far.

Having already been bitten in the ass by using their online forms, I decided I would call their local yard and inquire verbally. The lady I spoke to asked me to hold, at which point the call dropped. That's no big deal. Mistakes happen and I've made that one several times myself. I called back and she promptly apologized and successfully transferred me to another desk.

Where that other desk is though, I will never know, and really don't give a rat's ass at this point. After waiting on hold for about 20 minutes, listening repeatedly to recordings that invite me to use their web site for reservations (while failing to mention that their web site sucks the hind tit of a dead yak, and that by "reservations" they actually mean "bullshit"), I was once again cut off, left listening to a fast busy signal.

At that point, it became quite clear to me that they are still the same half-assed operation being run by the incompentent goons that cocked up the show two years ago. "U-Haul" is by far and away the worst-run slipshod operation on this side of the planet. Their service is atrocious, their vehicles are often not roadworthy, and they do not belong in the rental business. There are far better, properly run companies out there, and I very strongly recommend you seek them out. I will be renting from Hertz truck and van rentals this time around. I called their local office today and received excellent, immediate service from a polite gentleman who clearly knew what he was doing, and was very helpful in giving me detailed information on pricing and availablillity.

24-04-2008 New Job!!

Well, it's now official, with papers signed and dates set! I'm now signed up as the latest employee of a game development company in London, Ontario. I will be writing games and getting to see my work be used by more than just the people around me.

This thrills me to bits, although there is one drawback. London is about 600 kilometres from Ottawa, my hometown around which most of my friends and family reside. That being said though, it's the only significant drawback. For anyone reading this who doesn't know me, writing games is my "dream job". I've been programming since I was about eight years old, when I recieved my Dad's old hand-me-down Commodore VIC20. I got into writing full sized PC games in my early high school years, and quickly realized that this was the career I wanted. Ever since then I've been slowly working toward that career, and am very happy to say I have just taken a major leap forward - into exactly the position I sought.

I have to admit, I'm finding myself very stressed about it all. Starting a new job is stressful. Needing to learn the tools, the people, the environment. Moving into a new and unfamiliar city is also quite stressful. Put the two of them together and you've got more stress than you can shake a stick at. As I type this though, I realize that I've actually got it pretty easy in that respect. Take my sister, Rachel. She moved to Korea... oh... five years ago? eight years ago... teaching English as a second language. She excelled at it of course, and also met her love and started a family, but the initial stress of moving to a completely alien environment, on the other side of the world, to do a job you've never tried before, puts my own concerns to shame.

That being said, I think I'm going to save up a bit of money and buy a motorbike. That will allow me to get back to this end of the lake and visit friends and family much more quickly and easily than I could on my bicycle. In the mean time, I have a month to prepare for the new job and new home, and I do believe I'll do some studying.

21-04-2008 Injuns

As I "type" (using a stylus on a virtual keyboard) this message, the passenger train I'm sitting on has come to a stop. The attendant just walked down the aisle explaining that another train would be crossing momentarily and that we would resume travel then.

I have to admit, I was almost disappointed that it was such a mundane event. I already had visions of someone running down the aisle screaming "Injuns!!! Theym Injuns is attackin' the train!!". That would have been made all the more amusing by the fact that we're currently in downtown Toronto.

Sometimes life just isn't funny enough on it's own.

12-04-2008 Tour Nortel 2008

Once again I'm doing the Tour Nortel this year. As written on their pledge site, "Tour Nortel is a fundraiser for the CHEO Foundation, Ronald McDonald House and Candlelighters. Participants collect pledges and cycle, in-line skate or walk to help kids with cancer and win great prizes".

I will of course be cycling in this event, doing the 80km tour. To add a little distance to the trip, I plan on getting to and from the starting point under my own steam as well. That should bring my total distance for the day up to 120 km.

My goal here is to raise $200. If you'd like to make a donation, it will be going to a really great cause, and can be done by clicking here. If you'd like to contribute with action instead, you might be interested in volunteer roles that need to be filled, or even Registering to ride and start drumming up pledges!

07-02-2008 Learnin' Stuff

I'm now four days in to learning how to type on a Dvorak keyboard, and slowly getting better at it. In doing so though, I've noticed some interesting things about the way the mind works.

I expected that I would get better at typing certain letters as I continue to practice; that some would be learned faster than others, simply because they get used more often. That's not what's actually happening though. Instead, I'm getting better at typing certain sequences of letters. For example, I can very easily type the word "the", but to type "eht" takes slightly longer - even though they use the same letters.

This makes sense if you take a moment to ponder the matter. Our brains are very pattern oriented. We are extremely good at remembering sequences and patterns rather than raw tables of data. That's a good thing too. It is undoubtedly because of this that we developed language, mathematics, and innumerable other things that make us qualify as human.

This needs to be written up into a full essay, but I've neither the subject knowledge nor the typing speed to accomodate it at this time.

04-02-2008 Doing Dvorak

I've taken it upon myself to try learning the Dvorak keyboard. I have to say, It's a slow and arduous process at first. My brain is already heavily trained on qwerty, and that makes the transition tricky. So far, it has taken me 10 minutes to connect to this server (via a shell), and another twenty just to type up this paragraph.

Why then, you may ask, do I torture myself so? Well, it's probably a matter of geek pride more than anything else, but it's something I've wanted to learn for a while. It's well known that the Dvorak keyboard is faster to type on than the Qwerty model, and less stressful on the hands. My interest in this was recently rekindled by an article on BoingBoing, which links to a rather amusing comic strip about it.

So we'll see how far it goes before I curl up into a fetal position and shiver in the corner. Actually, I'm already seeing a fairly significant improvement just in typing this blog. That being said, I think both my brain and my hands have had enough of a workout on the subject for today, so I will end my writings here.

Day Two

The fight continues... Albeit a winning battle. A slow battle yes, but a winning one. I'm definitely typing faster, although still quite slow.

It's quite interesting how the mind wraps itself around these things. When I first learned how to type, it was of course on a "qwerty" keyboard. I learned it via the hunt and peck method though, and never really learned to type "properly" - quickly yes, but not properly. With this layout on the other hand, I'm learning the proper method (as hunt'n'peck doesn't really work when your keyboard has the wrong layout). As a result, I find myself thinking about it quite differently, and realize that this will lead to better typing once I've grown accustomed to it.

16-01-2008 I guess it's a blog now

The Bin

I never thought much of "blogs" - just another thing on the web to read. I think I was originally turned off from the concept because "web log" sounds too much like "online diary" for my liking. And yet now I find myself sporadically writing my thoughts on my site, dating them, indexing them, giving them titles...

Yep, sounds like a blog to me.

So rather than continuing to clutter up the main index page with them, I decided it was time to tidy things up and package them in separate section of the site. Lo and behold, I conveniently have "the bin" which was originally intended for a fairly similar purpose that never really went anywhere. So now I present the bin part deux - a large cavity where my general thoughts, ideas, writings and rants will reside.

I've made a few other touch-ups on this page as well, cleaning up the artwork section to properly incorporate the new mazes category, pulling out some no longer used code, and doing a bit of general upkeep.

So this particular blog (yes, I'll concede, it is indeed a blog), doesn't have much meat to it I'm afraid, just a quick "Hey! Changed stuff! Let's try it out!".

29-12-2007 Restorations

after before

I recently purchased an all-in-one scanner/printer/copier, and although the product is a bit of a pain in the neck in getting hooked up on a GNU/Linux system, I'm very pleased with the results. I spent my entire Saturday sitting in front of my computer scanning and touching up old artwork of mine that was unfortunate enough to land on a non-digital medium.

What really thrilled me though was a newfound abillity to restore damaged work. Many years ago, a hobby of mine was drawing mazes. I had made quite a few, but sadly lost several to water damage. I couldn't throw them out though; some of them were my better doodles and I just didn't have the heart to drop them.

So I was as giddy as a schoolgirl when I realized that I could now scan them into my computer and remove the atrocities that nature had bestowed upon them. The images on the right are a "before and after" of the work done on them. I'm so pleased with the outcome that I've added a new category to the artwork section of this site, with an assortment of mazes available for viewing (and solving!).

On a side note, I'll mention here that the signature shown on the image is not actually my real signature. Call me paranoid, but I'm sure enough of my personal information is already floating around online that putting my real signature out there would be somewhat foolhardy. With that in mind, I took it upon myself to replace my signature on the images with a signing of my name that doesn't match at all (yes, even in that "original").

26-12-2007 Things I'll never try again

Well, 'tis the season to be jolly, and damn I was jolly. Far too jolly actually. In the celebratory spirit of the season, I thought I'd join in the consumption of some baked goods with a bit of a magical kick to them. Actually, there's nothing magical about it. It's a matter of certain "special" ingredients in the cookies hitting my brain and having some interesting effects.

Feathers - revised.sketch.png

Now, one thing to keep in mind here is that I am not a regular participant in such endeavours. I could count on one hand the number of times I've smoked it, and on one finger (as of this past Sunday), the number of times I've eaten it. Of the few times I've tried it in the past, I haven't really found I got any real enjoyment out of it.

Why then, you may ask, do I try it now? Well, there are a few factors really, but the main one is the fact that the only times I've tried it in the past have been on occasions where I already happen to be very very drunk. I was still curious to see what it was like when my brain was otherwise acting normally. Add to that the festiveness of the season and the social nature of it, and it was almost inevitable.

So I tried it. I figured, "what the hell, let's see what it's really like", and chowed down on that cookie. Didn't notice a thing of course. I spent the next hour or two conversing while updating a PC.

Direction.sketch.png

It was toward the end of the conversation that I started to notice an effect. It was subtle at first, to the point that I didn't recognize what it was. I simply realized that for some reason, I was having a really hard time following the conversation.

It was when sitting in the car after departing that I started to think I might be feeling the cookie at work. No, don't worry, I wasn't behind the wheel, and the driver was stone cold sober. I had a wild ride sitting in the passenger seat though. I went through the full battery symptoms you typically hear about. After the first effect, being unable to follow the conversation, I noticed the second effect - the inabillity to concentrate on a particular subject. There was an interesting twist to this, in that although it seemed like my mind was wandering, it felt to me as though I was concentrating very deeply on a subject, but couldn't control what that subject was.

Mud.sketch.png

The next thing that happened was a brief spell of motion sickness. Thankfully, that passed quite quickly, at which point I started to get the classic giggles. Those of course turned into heavy laughter, which quickly became uncontrollable. It didn't help at this point that the person driving the car has a very good sense of humour, and as we all know, laughter is contagious. That started a vicious cycle and it took several minutes for me to control my laughter.

Controlling my thoughts on the other hand, took a bit longer. In order to avoid hysterically laughing again, I made a point of thinking grumpy thoughts. That actually helped. Despite how incredibly funny everything seemed to me at the time, there was a strong line of thought bouncing around my head in which I realized I wasn't really enjoying it deep down. I don't like loosing control of my mind, and that is what was happening.

Stone cloud.sketch.png

Around the same time, I started to notice hallucinations. I understand that this is not a common effect with this particular herb, but bear in mind, I haven't had it in years, and then only very sparsely. So yes, hallucinations. There were two that I recall. One was that my limbs and digits felt weird. A very odd feeling I can't quite capture in words. It was like having heavy rubbery body parts that dragged behind when I moved them. It's difficult to describe, partially because I don't clearly recall it, and partially due to the sheer weirdness of it. The other effect I do remeber well, as it lasted quite a while. My depth perception was messed up. It seemed like everything I saw was the same distance away from me, like a picture on the inside of a sphere. Walking around felt like I was walking on the inside of a ball.

I have to mention that I spent a couple of minutes alone in the car, when the person behind the wheel had to make a brief stop. As it happens, the song on the radio at the time was Pink Floyd's "Brain Damage", which is of course the perfect music when you're stoned.

I'll also mention here that I had to try at least one experiment, so I tried solving a Rubik's cube. For those of you who don't know me, I'm damn good with those. I can solve a regular 3x3 cube in about two minutes. In this case, I was working on the more challenging 5x5 cube, which usually takes me about ten minutes. This time, it was at least half an hour. Probably closer to 45 minutes.

Layer - 6.sketch.png

It was when sitting in that car that I felt another one of the commonly mentioned effects, paranoia. A lady walked by to enter her van in the adjacent spot, and I was terrified that I would look stoned and she would call the police. I also noticed this effect when we were driving down the road, at what I knew to be a casual pace. I was finding myself getting very anxious and worried that we'd be in an accident - despite the excellent skill of the person behind the wheel.

Another way it affected me was in artistic output. Upon getting home I laid down on the couch and started drawing. I think the need for artistic output was due to the fact that I couldn't concentrate, but still felt that I wanted to do something productive. The images you see strewn about through this blog are the ones I drew.

Hot head.sketch.png

I have a theory forming in my head, that being stoned is very similar to being in a dream. The mind drifts from thought to thought, without any control over where it's going. The reason for this seems to be that two key skills in the human brain are affected.

First, concentration is gone. It's right out. The mind quite happily wanders around, stumbling into things and tripping over its own feet. To actually ponder a matter with any seriousness is out of the question. Second, short term memory is out the door. My memory of it at its worst is quite hazy, and while it was happening, I was very much aware of this effect. At one point, someone would start a sentence, and I'd comprehend every piece of it, but forget the first half after hearing the second. In both of these behaviors, it is very much like the state of one's mind when dreaming.

Box Head.sketch.png

As entertaining as this may be, I can say quite conclusively that I do not like it, and will never partake in it again. I value my mind too much. Even now, three days later, I still have a hard time concentrating. Not nearly as much as in the previous days, but it's still there. I expect I'll no longer notice this effect tomorrow or perhaps in a couple of days, but I don't know how long it will take to be actually out of my system and not affecting me. Even today I noticed myself taking longer than usual in solving the aforementioned Rubik's cube - making mistakes that I normaly wouldn't.

21-11-2007 Integrals ROCK!

Given:

    A = πR²
    R² = x² + y²
    ∴ y(x) = (R² - x²)1/2

Then:
V =
R
-R
π ⋅ y(x)2 dx

∴V =
R
-R
π ((R² - x²)1/2 )2 dx

V = π
R
-R
(R² - x²) dx

V = π
R
-R
R² dx   -   π
R
-R
x² dx

V = πR2
R
-R
dx   -   π
R
-R
x2 dx

V = πR2 ( x )
 R
 
-R
  -   π (
x3
3
)
 R
 
-R

V = πR2 ( (R-(-R) )  - 
π
3
( R3 -(-R3 ) )

V = πR3 + πR3 - πR3 /3 - πR3 /3
V = (2 - 2/3)πR3

V =  
4
3
πR3

Not long ago, maybe a few weeks, I thought I'd refresh my memory on the trifle of calculus I learned in my OAC classes in high school. I started by going out and buying a new book on the subject, and I must say, I'm very happy with the purchase I made. The book is The Humongous Book of Calculus Problems, by W. Michael Kelley. It has 1000 questions in it, which get progressively more challenging throughout the book. With each question, he walks you through a step-by-step procedure of solving it, and has a battery of side notes to clarify things. It's a great book to learn from, and it's what I've learned from this book that inspired me to write this post today.

I remember a time when I was quite young, still in grade school, and learning some basic geomety. It is a specific moment that I remember, when I wondered if I could figure out the volume of a sphere based on the the equations I knew for a circle. I didn't of course. For a kid that age though, I'd say I had a pretty good grasp of things. My idea at the time involved taking the area of a circle, and multiplying it by half the circumference of that same circle (the logic there I won't bother to explain). Of course, it didn't work, and I later learned that the volume of a sphere is 4/3πr³.

Although that equation is of course correct, I was rather disappointed when I learned it. I did not understand why that equation worked, but merely memorized it for my later convenience. That stewed in the back of my brain for years, until I hit a question in the aforementioned book which I was very happy to solve. That question being exactly what I wanted to know then: given that the area of a circle is πr², show that the volume of a sphere is 4/3πr³

The way to solve it is like this: Take the basic equation for a circle:
x² + y² = r²
Now rearrange that equation, solving it for y:
y² = r² - x²
y = √(r² - x²)
This gives you the y-coordinate(s) of any point on a circle, given it's x co-ordinate and radius.

The trick here is to envision that circle as a projection of a sphere. If you look at the circle in 2D on a piece of paper, you can envision it as being merely a center slice of a 3D sphere. Now imagine that sphere divided into slices that stick out of the paper toward you. In that case, that same equation represents the radius of those slices.

Slicing things is of course one of the fundamental parts of calculus. It's by using integrals that we can effectively take an infinite number of slices, and add them all together, giving us the volume of the sphere.

In the case of a sphere, all of those slices are circles, their area being πr². Their radius will change depending on what part of the sphere we're slicing them from. As mentioned above though, that radius will be √(r² - x²). With this information, we can work out the volume of the sphere as a whole. The steps in doing so are what you see on the right.

I have to say, being able to work that out on my own steam really made my day. Now, the coolest thing about calculus is that you can take one equation, and transform it to give you other equations. If you take that same equation that we have for the volume of a sphere, we can actually take it's derivative to get the surface area:
V = 4/3πr³
∴ V' = 4πr²
∴ A = 4πr²
I'm really pleased to be able to gain a good understanding of why those equations are as they are.

27-09-2007 Multiplication tricks

I recently had a discussion with a good friend of mine, Gordon Bonnar, about the reason why certain tricks for checking the factors of numbers work. The trick we discussed in particular was the commonly used one to know if a number is divisible by three: if the sum of the digits is divisible by three, then the number itself is.

For example, take the number 123. We can quickly see that it's a multiple of three by adding the digits, and seeing if they add up to a multiple of three. 1 + 2 + 3 = 6, so we can see that 123 is divisible by three. This is indeed true, and 123 divided by 3 gives us 41.

The first thought that went through my head on this was that it has to do with the base the number is expressed in. That although it works perfectly in decimal, it may not work in hexidecimal, binary, or various other bases. To test this then, I tried applying this same rule in other numeric bases. The first one I tried was binary, and could immediately see that it does not work. For example, in binary, the number 15 would be expressed as 1111. 1 + 1 + 1 + 1 is not divisible by three, and yet the value itself is.

This is more important than it might at first seem. The fact that it only aplies in certain bases means that the rule is not applicable to the true value of the number. 15 in decimal is exactly the same value as 1111 in binary. There is no difference between those two values; they are identical. The only difference you see is the notation used to express them. This is significant because it means that the rule for checking divisibility by three is not applicable to the value itself, but only to the notation used to express that value.

Much to my surprise though, I found that it does indeed appear to work in other bases. For example, it seemed to work in hexidecimal, and in base 7 when I tried that. It was in seeing which bases work and which ones don't that I realized why this rule works.

When you write a number in decimal, which is how we use numbers on a day-to-day basis, you are expressing it in a numeric base that is one greater than a multiple of three. That is to say, the numeric base we use, 10, is one greater than the value 9, which happens to be a multiple of 3.

Now let's look at multiples of three, not looking as much at the value of the number, but at the digits used to describe that number. Our first three multiples are 3, 6, and 9. What is special about these numbers is the fact that they are each written with their own unique symbol. The first change comes when we hit the next multiple, 12. This is where the value we're expressing becomes greater than the base we're working in. In this case, it does not have a unique symbol. Instead it is expressed by combining two other symbols, 1 and 2.

Consider then why we use the values 1 and 2 to write out the next number. Beyond the fact that this is how the value twelve is expressed, why exactly does it end up being those two digits? There are two reasons why:

First, the value we are incrementing by is less than the base we're expressing it in. That is to say, 3 is less than 10. This is important because it means that each time we increment the value by 3, the "tens" column in the number can only do one of two things: it can increase by one, or it can remain as it is. It can never increase by more than one, because for that to happen, the value we're incrementing by would have to be greater than the base we're working in.

Second, the largest multiple of 3 which is less than 10, is 9. It is important to note this, and realize that 9 is exactly 1 less than the base we're working in, 10.

Look then at what happens to the values of the digits when you add the value 3 to the value 9. The simplest way to look at this is by adding 1, three times in a row. 9 + 1 = 10. So we can see that the "tens" column increases at this point, and the "ones" column is reset to 0. Add another 1, and the "ones" column is increased by one, leaving the "tens" column untouched. Add it again, and the same thing happens, leaving us with the digits "12" and the number twelve.

Notice then that the number used in the "ones" column is now one less than the value 3. This change occurs each time we pass a multiple of ten. So on the first run, the "ones" column contains the values 0, 3, 6, and 9. Then we increment the "tens" column by 1, and the "ones" column goes through the values 2, 5, and 8. Again, the "tens" column is increased by 1, and the "ones" column then goes through the values 1, 4, and 7. Each time the "tens" column is increased by one, the set of numbers used in the "ones" column is decreased by one. As a result of this, the two columns add up to a multiple of three.

This continues until we reach our next digit and go over 100. At that point, we jump from 99 to 102. But because the base we're working in is one greater than a multiple of 3, we see the same effect. Our "tens" column goes from using the digit "9" to the digit "0". Both of those values being multiples of three, this makes no difference in the divisibility of the sum. The "hundreds" column also changes though, going from "0" to "1", so the combined effect of these two columns is to add one to their offset from a multiple of three. In the mean time, the "ones" column continues in the same pattern as before, decreasing the set of digits it uses by one. The net effect then is to maintain that balance in the sum of the digits.

This pattern continues indefinitely and is the reason why our division by three rule works. There are a couple of interesting observations that can be made from this:

*For the cynics out there, that number, 1A73695194 (base 11) is equal to 4644366335 in decimal, which is indeed divisible by 5.

09-06-2007 My bicycle is now laminated

A couple of weeks ago I posted a note on facebook saying that I was lamenting my bicycle. A friend of mine commented that he had misread it as saying that I was laminating my bicycle. I thought that was such a great idea that I had to try it out. I've completed the job now, having put together a full rendering of my bicycle, laminated on to the street.

I put this together using Blender, a really nice open-source 3D modeling/animation/etc. program. One thing that separates this from a lot of my previous work in Blender is that fact that I didn't feel the need to touch it up with GIMP afterwards.

In making this I learned a couple of aspects of blender that come in very handy. The laminated layer was made by creating a flat grid of verticies as an object above the bicycle, and then using "proportional" editing - which makes the editing of one vertex affect the verticies around it in a dissipating manner - to drag the points down on to the bicycle and the surrounding ground. The other thing I learned was how to apply more than one material to the same surface (rather than using separate objects to represent separate materials. This is how the white strips on the asphalt are painted, despite being the same surface as the rest of the ground.

02-05-2007 The AACS licensing authority is a bunch of idiots

Yup, that's right, the people who license AACS keys have the wit and intelligence of a retarded piece of cheese. Foul smelling retarded cheese at that, like parmesean or limburger that never graduated from curdling 101. They seem to be suffering the ridiculous delusion that they have some legal right to supress the sharing of a numeric code online. This code can be used to do things such as back up and play HD-DVD disks on your computer, circumnavigating the DRM that prevents you from using the product you purchased in ways that they don't want you to.

As stupid a business model as it may be, I'll grant that they might be peeved that their DRM is as good as cracked. Pity for them. But the fact is, the cat's out of the bag, and there are two key things they don't seem to understand:

  1. You can't patent, copyright or otherwise try to prevent other people from using a number. No matter how you argue it, you've got nothing. Even if they tried to use the DMCA to bury it in the U.S. they wouldn't have half a broken ankle to stand on. Consider, even if they found the most backwoods judge and convinced him that "Arnezami" or "Muselix64" who cracked the HD-DVD system were liable, that does not apply to John Q Public who found this number online. No breaking of the law is done in reading a document or sharing a number.

  2. You can't supress information that's leaked on the Internet. If it's out there, and people want it, you ain't stoppin' it. And just for an extra kick in the pants, if you try to suppress it, people make a stink, which makes even more people aware of it. It's a vicious cycle that you can't win. One might be inclined to compare the Internet to a handful of fine sand; you can't contain it. I think that's the wrong analogy though. It's more like a handful of uranium-235. Not only can't you contain it, but if you try to, it will explode in your face and leave a far more devastating mess than if you simply let it dissipate.
On a final note, 09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0, and if you want to read up on this, I'd suggest starting with this article on boingboing.net.

28-04-2007 Math puzzle solved

I'm happy to say that my answer to the puzzle about the falling stick is correct, and I was able to demonstrate it with a quick little C program that actually performs the act of dropping the stick on the plane a few million times, counting how many times it crosses a line. The outline of how it works goes like this:

Anyone not familiar with some trigonometry details may question the logic of that, so I'll break it down a litte further now.

The program works by picking a random location for one end of the stick, selecting a random angle that the stick falls at. Given those two pieces of information, it then calculates where the other end of the stick falls.

Because our stick has a length of 1, the location of the second end of our stick will be the location of the first one, with the cosine of our random angle added to the x-coordinate and the sine added to our y-coordinate. I was going to write a big explanation of why this is true, but that would take too long and I assume anyone who's actually interested either understands already or can go pick up a good geometry textbook.

We're not concerned about the x-coordinate though, only the y-coordinate. We want to see if the second y co-ordinate falls betwen the same two lines as the first one. If it does, then the stick does not cross a line.

With that in mind then, we know that our random point is between 0 and 1, so if we add the Δy of our stick (which, remember, is equal to the sine of the angle) to our point, then we'll know that the stick crosses a line if that new point is not between 0 and 1.

And that's how it breaks down logically. I'm quite pleased to say that it does indeed give exactly the numbers I expected, and the answer to the puzzle is indeed 2/π, or aproximately 63.66%.

If anyone is at all interested, here is the very short and simple C program I whipped together to demonstrate this:

14-04-2007 A good math puzzle

This blurb is about a puzzle that was presented to a math class I attended in college many years ago. I thought about it again recently, and think I have the answer. Sadly, I can't find the professor who presented it, so confirming it is tricky. I think I have it right though, so I present it here, and if anyone can show me that yes, I'm right or no, I'm way off, I'd be quite grateful.

The puzzle is this:

Imagine a plane (no, not the flying kind, but a surface), that is marked by a continuing series parallel lines. For the sake of this question, you can imagine these lines going on infinitely, and there being an infinite number of them (covering our infinite plane). These lines are all exactly the same distance apart. Now imagine a straight stick (or in this case, a line segment) is thrown on to the plane. The length of this line segment is exactly the same as the distance between the lines. It is dropped at a random angle in a random location. What is the probability of it intersecting one of the lines on the field?

I've thought about this a few different ways, but only one really seemes to make sense. This is the answer I've settled on:

For ease of comprehension, let's envision all of our field lines as horizontal ones. In truth it doesn't really matter, as the angle of them depends on our frame of reference. In this case, we'll say they all have a slope of zero.

To consider the overall probablillity of it hitting a line, we first have to consider the probablillity of it hitting a line when it lands at any given angle. That's actually fairly simple to see, although I have no idea how to prove it mathematically. First, keep in mind that the stick has two dimensions, Δx and Δy. As our lines go on indefinitely, and there is nothing to collide with except those lines, we can say that the horizontal range of our stick (Δx), does not matter. What does matter is the vertical range of our stick, Δy.

By observation, we can see that the chance of our stick crossing a line will be equal to its vertical length (Δy), divided by the actual distance between the lines on the field.

So what is that vertical length? Well, with a little bit of basic trig, we can see that it will be the length of our line segment multiplied by the sine of its angle relative to the lines.

This means that the probability (hereafter called "P") of the segment intersecting a line will be equal to the sine of our angle (we'll call it "a") multiplied by the length of our line (which we'll call "L"), divided by the distance between the lines (which is also equal to L). As a result, we get:

	P = sin(a) × L ÷ L
	P = sin(a)
So the chance of it crossing a line at any given angle is equal to the sine of that angle.

With that in mind then, we know the chance of it hitting a line if it's dropped at a given angle in a random location. What we want to know though, is what chance it has of hitting a line if the angle is random as well. To start, let's consider a graph of our probability over potential landing angles. The total range of our probability would be from 0 to 1. With the angle, (in radians), we only need to consider the range between 0 and π. This is because the range from π to 2π gives us an identical set of numbers and we are not interested in the numbers themselves, but the ratio between them - which remains the same. The graph would look like this:

Graph of probability over angle

This graph shows us the probability of the stick hitting a line, depending on the angle it falls at. In that case, its overall chance of hitting a line would be the area betwen this curve, "y = sin(x)" and the base of our graph, "y = 0", divided by the total area of the graph.

So, to calculate that we would take the integral of y = sin(x), for the range 0 to π, which gives us the area under the curve, and divide it by π, which is the total area of the graph.

The integral of the sine function is the negative cosine, so we get:

p  =  
1
π
π
0
sin(x) dx   =  
-cos(π) - (-cos(0))
π
  =  
cos(0) - cos(π)
π
  =  
1 + 1
π
  =  
2
π
  ≈   0.6366

So overall, our chance of intersecting a line ends up at approximately 63.7%

The catch here is, I don't honestly know if I'm right. I could be way off. I think I've got it right though, so if anyone would like to confirm it one way or another, I'd be glad to hear some feedback.

19-08-2005 2005 Bicycle Tour - Day 7

I'm Home!!! After three days of hellish travel, I'm home and resting my buttocks on a comfy office chair. I must say though that if I ever do a tour of that sort again, it'll be on a motor vehicle of some variety. So here's a run-down on my past three days:

Wednesday:

We'll start with the 17th of August, after typing in the previous journal. This was by far and away the most horrific day of my trip and in fact, the worst day I've had in a long, long time. I had a late start on the day, having gone out with Benny to grab breakfast and some things I would need on the road. I also took my time packing my bags, double-checking my maps, finding a bicycle shop nearby and so on. As a result, I didn't actually get out the door until 11 O'clock.

I did get out though, and headed to the aforementioned shop. After having them replace my wheel and also purchasing the piece of hardware I was missing in Kaladar, I got out of that shop at 1:00. I was suddenly flying down the road with great speed, thrilled and excited with what an amazing difference a new wheel made. Thrilled until I realized that the difference in speed was not due to the condition of the wheel, but the fact that I had inadvertently left my loaded saddle bags sitting on the floor of the shop I had just left.

Ah well, I hadn't gone too far before I noticed it, so I turned around, picked them up, and took off again. I was feeling great and thinking I'd make excellent time, having the wind in my favour and a new wheel on the bike. Needless to say I was rather disappointed when I had gone a mere ten kilometres or so and got a flat on that same wheel I had just replaced. I chalked it up as my fault, having told them to pump it up to 120 psi and realizing later that it only took 110 (I learned later that this is not where the problem was). Conveniently, I had this flat across the street from a "Canadian Tire", and was able to acquire an extra tube (to replace the spare I would now be using), and some hockey tape (to line the rim, preventing the tube from exploding into the little holes that the spokes connect to). After much fiddling around, purchasing the wrong size tube, not being able to return it because it would have meant lining up for a ridiculous amount of time and filling out piles of paper work, and getting interrogated about my travels by a nice lady and a little boy, I finally had everything reassembled. It had taken a long time, and was now pushing 3:00 in the afternoon, but I was once again on the road.

Once moving though, I was a little upset to find that my tire was soft. I filled it with this nifty device that uses a CO2 cannister. Unfortunately, after pumping up this tire, I only had one cannister left. On top of that, I was concerned about the condition of the tube I had used because it was an older one that had been strung up under my bicycle seat for a rather long time, and I had seen some evidence of wear in it. This left me with a dilemma. If I pumped up the tire, it might break and leave me screwed with no way to inflate the remaining one. On the other hand, if I ride too far with that tire so soft, it might be damaged.

The solution of course, is to go buy a small portable pump that I could inflate it with. I did exactly that, and was once again moving along nicely until I had gone a few more kilometres down the road and it went flat again. I wasn't too upset, having half expected that anyway. Conveniently, this happened when I was only a half a block away from a bench outside a bar, where I could comfortably sit down and work on replacing the tube.

I had the tube removed and replaced, and the new one pumped up within ten minutes. Ready to go again, I picked up my bike, set it down on the road again and listened disgustedly as it made the unmistakable "PFFFFSSSSSSSSsssssssss...." sound of the tube once again popping and all the air leaking out. I had to laugh at this, my only other option being to cry. At this point, being out of replacement parts, and rather disillusioned about my ablillity to repair things properly, I approached some gentlemen who were sitting on the patio of the bar I had sat in front of. They had been watching me work on it, and laughed along with me when it went flat again. It is these four gentlemen I have to thank for turning my day around. Approaching them to ask if they knew of any bicycle shops nearby, I was hoping merely for a "yeah, just a few blocks that way" type of answer. Instead, one of them lent me his cell phone to call the nearest one (which we had found in a phone book provided by the nice lady who was tending the bar), making sure they had everything I would need. Once finding it, another one of these guys actually drove me and my rear wheel to that shop in his car, waited outside the bike shop for me while the work was done and spare parts purchased, and then drove me back to the bar where his friends had kept an eye on the rest of my bike. I was blown away by this act of kindness. I thanked them profusely, bought a beer for the gentleman who had escorted me to the bike shop, and headed on down the road again.

Incidentally, it was in that second bicycle shop that I learned why I had been getting so many flats. I was told that when applying hockey tape to line the rim of the wheel, you need two layers of it to withstand the pressure. They had only applied one in the shop at which I had purchased it.

My day went pretty smoothly after that. After a fair bit more riding I was finally past Oshawa and all the larger cities in that area, and getting pretty decent speed, having the wind in my favour most of the way. Eventually I stopped at a motel in a small town called Welcome, which is just north of Port Hope. I had spent about nine hours on the road that day, and gotten only 100km out of it. Only four of those nine hours were actually spent riding.

Thursday:

Determined to get back to Ottawa in three days I took off again, planning on covering at least 200km before dusk. My original plan had been to follow highway #2 all the way up to Kingston, stay there for the night, and then go up through Perth and into Ottawa from there. Having the wind in my favour, it would have been a great tour. Unfortunately the wind, being the fickle tramp that she is, had decided to change direction overnight. I was now fighting a strong, cold wind and could not move my bike any faster than 20km/h, which is slow even with all my luggage. By the time I hit Cobourg, I decided I had to escape the nasty wind, and would do so by moving north, away from lake Ontario. I did this in the hope that it would change direction or at least be weakened by passing over the land. This worked to a certain extent. Although I was still fighting the wind, it was a little gentler.

I ran into a minor problem when I stopped in Hastings, a small town about 10 kilometres south of highway #7. I was not able to pull my left shoe out of the clip-on pedal that it was attached to. After much poking and prodding with a screwdriver, I got it out and found the cause of my problem: one of the two bolts that connects the metal clip to the bottom of my shoe had fallen off. Conveniently I had only noticed this problem after stopping almost immediately in front of a "Home Hardware" store. After walking in and paying five cents for the bolt I needed, I was once again on the road.

When I got up to highway #7 and started heading east, I came across a gargantuan traffic jam. I passed by at least three kilometres of vehicles lined up all the way through and well past the town of Havelock. I must say I got quite a few odd looks from them as I went by. I was passing people who had already passed me at least half an hour earlier. It turns out this traffic jam happened because of a social event involving trailers and winnebagos on the far side of town (which would explain the rather large number of such vehicles in that traffic jam). They were all trying to make left turns off the rather busy highway. On the plus side, once I passed all that traffic the road was nice and clear, being thoroughly clogged up behind me.

Despite the wind I was feeling pretty confident (or egotistical, depending on how you look at it), and decided I would try to get to Perth that day. Going up to highway #7 and then East from there, it would mean doing about 235 kilometres that day. I've done that kind of distance before, and could have done it again if I had another hour's daylight. Alas, the sun is somewhat unrelenting about the length of our day, so I came close, but not quite. I managed to put in 198km before my shadow became worryingly long. I stopped at a payphone near Sharbot Lake, about 37km west of Perth and called Todd and Leanda Bracegirdle, who I'm always happy to call family (Leanda being my Mom's sister) and who also live nearby there. Despite my audacity to call collect from a payphone (not having enough change for a long distance call), they were of course quite welcoming and agreed to meet me on the road toward their place.

As soon as I pulled out of the parking lot which hosted the payphone, one of the spokes on my new rear wheel broke. I suspect they don't deal well with heavy acceleration. Ah well, I didn't bother to fix it then as it would be about an hour's work. I simply trued the wheel by adjusting the spokes around the broken one, and carried on down the road. Eventually I met Leanda, who drove me back to their place in a comfy, warm van. I was very happy to be there. Not only did I get free shelter for the night and an excellent dinner, but also the use of the shower and laundry facillities, as well as entertainment and good company.

Friday:

And finally we have today, the last leg of my journey. I had a great morning, being fed a delicious breakfast and given time to repair my wheel once again. I also had clean clothes, and was given a lift into Perth, skipping all the gravel roads leading into town. Unfortunately the weather was quite poor today, having rain pouring down all day. I was kindly offered another day and night of rest at the Bracegirdle residence, but decided I wanted to get home at this point. It was an almost uneventful day. Aside from the rain, the only hinderance to my trip occurred when the other bolt fell out of my left shoe clip. Not wanting to find another hardware store and go through replacing that bolt while getting drenched, I decided to simply ride the last fifty kilometres with my left foot constantly on the pedal. This led to some difficulties when coming to a stop, as I usually leave my right foot on the pedal and balance with the left one on the ground, but I got home and am now warm and dry.

Unfortunately, my spedometer does not handle the water as well as I do (and that's saying something, 'cause I sure as hell didn't enjoy it). As a result, I don't know the exact distance or or time I took to get into Ottawa today. I do know it would be aproximately 83km (maybe a little more, but not much). I know this because the majority of this route is one that I take quite frequently, and I do know that when I merged with that regular route, I had gone 18km. I also know that at the point where I merged with it, I still had about 65km to go.

17-08-2005 2005 Bicycle Tour - Day 5

It is with a certain degree of disappointment that I turn around at this point, but that is what I am doing. My bike is in ill repair, my bum hurts, and I would very much like to go home, relax, and bum around town doing nothing.

So I will be heading east from this point on. I believe I will take highway #2, which goes along the southeast border of Ontario, and eventually turn up toward Ottawa when I hit Kingston. That highway was actually suggested by a complete stranger I encountered at a bus stop here in Toronto, while waiting on an occupied payphone. It looks like a good route once I get out of the metropolitan area and out past Oshawa. I think I'll just push myself until I feel I've gone too far, and then hit the first motel I can find.

Before doing so, I'll hit a bicycle shop here in Toronto to replace my rear wheel. with any luck, that will make the ride somewhat smoother, easing up on the sore bum I currently get after a paltry 80km. I don't know if I will be able to do any more blogs before getting back into Ottawa, as I don't know where I'll be stopping or whether or not they'll have internet access. In other words, if you see no more notes for the next three days, it still doesn't mean I'm in any sort of trouble.

16-08-2005 2005 Bicycle Tour - Day 4

It's Tuesday and I'm now sitting at Ben LaHaise's place in Toronto, happily making use of his computer. I have to say this man has the sexiest computer I have ever seen. The monitor is an insanely huge LCD that's so big I actually had to drag the window in which I'm typing closer to myself to see it better.

My trips over the past few days have been good, although tiring and semi-eventful. On Sunday, after I departed Mom's place and headed out for the MacDonald residence, I got a little bit lost finding my way from county road twelve to the 509. I inadvertently took a detour that had me running parallel to it instead of towards it. Eventually I realized the error of my ways and turned around, taking the appropriate turn onto a back road whose number currently eludes me. Eventually I got there though, and ate very well. I have to say those two have some of the cutest kids in town. Their oldest son, Hugh, who is just over two years old, could charm the habit off a nun. I departed their place the next morning feeling well fed, energetic, and ready to tackle the road

This brings us to the 15th, when I tackled highway seven toward Peterborough. This is a very busy highway and I would not recommend it to an inexperienced rider. although large portions of it have a paved area about two feet wide to the right of the rightmost lane, there are many portions that do not. I actually pulled off onto the shoulder at one point, when there were fleets of large trucks aproaching me from both ahead and behind.

The traffic didn't really bother me much though, as I take the eastern end of that highway all the time. My trip took a down turn just before I hit Kaladar, as one of the spokes on my rear wheel broke. This wheel has a bit of history for that, and I wasn't too worried. Although this would slow me down for a while, it would not leave me completely screwed, as I had brought spare spokes with me and the tools required to replace them. That is what I thought at least. After several minutes of fiddle-farting around with the casette (the gears on the bike, which I need to remove in order to replace this spoke), I realized that I was missing a necessary tool. I did not have a small haxagonal device that holds on to the casette as I rotate the sprockets. Apparently this tool is on vacation too, happily sitting on a shelf in my room in Ottawa. I managed to true the wheel sideways at least, meaning that it would not be rubbing the brakes, and had a bumpy ride the rest of the way to Peterborough.

Upon arriving in Peterborough, I stopped at the first sign of a semi comfortable place to sleep, in this case a "Best Western" hotel. I have to say that, as much as I did not want to pay a lot of money for the night, it was very nice to sleep on a big, fluffy, queen-sized bed. I woke up feeling very refreshed and managed to put down enough high-energy food that I was almost shaking before I left.

And that brings us up to my trip today, from Peterborough to Toronto. My initial plan was to take the 115 from Peterborough south until I hit the 4 west, which goes right through Toronto. I could see by the map that the 115 is a separate lane, heavy-traffic highway, and was very carefully watching to see if there were any "no bicycle" signs. I saw none, and as far as I know it's only 400's and otherwise marked roads that are closed to bicycles in Ontario. So, not having seen anything to dictate otherwise, I headed on down that highway, and moved quite quickly too. The lanes are wide and there is always a good chunk of asphalt to the right of the outside lane, leaving enough room for vehicles to get around you. I ran into problems just before reaching highway 35, which runs up north towards Lindsay. A construction zone had decided to impose itself at that point, narrowing the road down to one lane. One rough, messy construction lane that is not wide enough to share between a bicycle and even a small automobile. One moron squeezed past me and damn near ran me off the road, at which point I took the center of the lane and went as fast as I could. Thankfully, this was on a sharp downhill slope and the next exit was near the bottom of that hill. Also since the speed limit had been reduced to 80 km/h, I wasn't going too horribly slow relative to the traffic (between 55 and 65 km/h). The real kicker though, is that once I got off the exit lane, and looked at it's corresponding entrance lane, I could clearly see one of the aforementioned "no bicycle" signs.

This of course left me to plot another course into town. Which I managed to do. It was in fact very nice, the traffic was quite light compared to the 115, and a very large portion of the trip was downhill. Eventually I got down to the #4 (or Taunton road), and was back on course.

The rest of this ride was not too bad. another one of my spokes broke when I passed through Oshawa, and the traffic in Toronto is nasty (almost as bad as the hills). I'm here now though, feeling fresh, clean and very hungry. On that note, I'll end my writing here and go eat out somewhere.

14-08-2005 2005 Bicycle Tour - Day 2

Well, I'm off. It's funny how things work out. I was under the impression that I would be able to write a note yesterday and not today. As it happens, my Dad's computer is not currently hooked up to the internet, so yesterday was out. However, despite what I thought previously, my Mom's computer is not completely kaput. As a result, I can do a quick note of my travels as I pass through Lanark.

My first day out was somewhat uneventful. The weather was perfect. I rode from Ottawa down to Bishop's Mills (south of Kemptville) and out to my Dad's place from there. A nice little ride with a grand total of 74.36km. I completed it in two hours, fifty-eight minutes and eight seconds, leaving me with an average of 25.04km/h. I'd say that's not too bad considering the fact that I was taking it easy and had to slow down in a few spots to find my way.

Today I cheated. Dad was kind enough to offer me a ride up to the nearest asphalt road, which I happily accepted since it was raining and I did not feel like riding on ten kilometres of bumpy gravel. Of course, by the time we got to the paved road, Dad realised that he needed to go to Smiths Falls anyway, and, given the weather, I would have been hard pressed to say no. That means that I'm now in Lanark, having only gone 36.93km today. Once my clothes have finished drying I'll be on the road again and probably only have to do another 30k.

Ah well, I suspect I'd have enjoyed this ride far less if I did do the whole trip, as I would have inevitably been caught in the rain. Anyway, that's all for today. I probably won't be writing for the next two days, as I know the residence I'll be resting at tonight is Internet-free, and I'll be hitting a random motel the next day. So that's all until I hit Toronto!

12-08-2005 2005 Bicycle Tour

It's 2300h on the 12th of August and I'm getting ready for and excited about a long trip on my bicycle. The original plan is to bike a round trip along the southeastern end of Ontario, from Ottawa to Windsor and back. I'll warn any readers in advance that I may have to cut the ride short and turn around at Kitchener.

If I go with the original plan, the round trip should be about 2000km, and it will take me the full two weeks plus the surrounding weekends to accomplish. If I use up the full 16 days my schedule has granted me, then I would need to ride aproximately 125km a day in order to do this.

Unfortunately, I have not been doing enough cycling to get ready for this and may have to cut my plans back a bit. I was slapped in the face with this revelation two weekends ago when I rode my bicycle up to my Aunt and Uncle's cottage for an annual family party. I was planning on riding there one day, resting the next day, and then biking back the following day. It would have been around 200km each way and I was looking at this as being the "acid test". If I could make that trip I would be fine with the one down to Windsor and back.

I felt great on the way up to that cottage, or at least for the first 100km or so. After that I started to feel a bit sore, but still enjoyed it for a while. I was probably around 150km out when I started to "bonk", which is a sporting term that refers to a state one is in when their body has drained all of it's immediately available energy. After I had gone 170km, two of my Mom's sisters drove by and picked me up, saving me a good two or three hours of agony going the rest of that trip. To top it off, I got a ride back toward Ottawa as well on my return trip, meaning I only needed to do about 80km that day.

To summarize, if that was the test run, I failed it miserably. That brings us to plan B. I will ride from Ottawa to Kitchener, adding an extra day to that stretch as well, making the rides a little shorter. When I reach Kitchener, I'll decide then whether to go all the way to Windsor or to turn around at that point. If I do turn around then my round trip will probably be only about 1200km.

So here's my plan for the first leg of the journey:

  • Sat. Aug. 13th
    Ride from my place in Ottawa to my Dad's place near Bishop's Mills. That should be about 65km, a nice, gentle start to the trip.
  • Sun. Aug. 14th
    From Dad's place to the home of Ben and Anna-Maria MacDonald, some friends of mine who live near Mississippi Station and are kind enough to put me up for the night. I'll also stop by my Mom's place in Lanark en route, and pick up the sandals that I accidentally left there last time I was around. That should be about 100km.
  • Mon. Aug. 15th
    From Ben & Anna's place to Peterborough, where I'll hit the first motel or B&B that I can find and crash for the night. That should be just shy of 170km.
  • Tues. Aug. 16th
    From Peterborough to Toronto, where I'll meet an old friend of mine, Benjamin LaHaise, and make use of his couch for the night. That'll be about 130km.
  • Wed. Aug. 17th
    From Toronto to Kitchener, visiting my Mom's sister Donna-Lee and the rest of her Murphy troupe. That trip should be about 120km. I should probably stop in Georgetown on the way, visiting my grandmother and some of my Dad's siblings (I suppose I'd better call them. I have not yet done so as I type this sentence).

And that is where we hit the aforementioned decision time. If I'm feeling great at that point, I may keep on going, stopping in London, Chatham, and then Windsor. That plus the return trip in the same number of days would have me back in town the night before I return to work. If I'm not feeling so fine at that point, I'll turn around and head back, leaving me with five days to lollygag around Ottawa before returning to the office.

As a final note, I will try to update this journal on an almost-daily basis, but if I don't update on certain days, it doesn't mean I'm dead on the road. For instance, I know I won't have internet access on the evening of the 14th, and possibly not on the 15th either. But aside from that, I'll try to keep posting.