Blatantly abusing the Windows search function: a very lazy note-taking idea

August 31, 2010

Often, as I am minding my daily business, I would suddenly have an interesting thought, or some idea. Being likely to forget it a few minutes later, I would want to write the idea down. But being a lazy and slightly disorganized person, I would grab the nearest pencil and scrap paper, scribble down a few words, and throw the piece of paper aside somewhere.

Usually I would never retrieve that piece of paper again. But occasionally I do want to read the note I wrote. After a few minutes of searching I would usually find the piece of paper I needed. If I didn’t, oh well, it probably wasn’t that important anyway.

But, as you can imagine, this quickly gets out of hand.

Now you would like to do do the note taking on the computer, instead on small pieces of paper. After all, losing files is harder on the computer right?

But how would you do this? In the computer world it’s a bit harder to ‘throw aside’ a file. You have to give the file a name, and put it in some directory, essentially forcing you to be organized. Or if you don’t, files clutter up your computer desktop even faster than sheets of paper clutter up your actual desk.

So being the geek I am, I wrote up my experimental, software solution. Then writing a note would go as follows. You open up command prompt, and enter the note command:

Type up whatever you want, and then hit save:

So your note is saved in some obscure directory of your choosing. Now the Windows 7 search is pretty good (Windows Vista works too) that as long as your directory is indexed, Windows-F and typing pretty much anything in the search bar would quickly bring you to the file (it searches file contents):

Searching for “phone ashley” takes me directly to the note. The program just takes what we’ve written, and saves it in a unique file that also has a datestamp on it. For example the first note written on a day would have _1 appended to it, then _2, and so on.

I’m not yet sure how practical this idea would be, but here’s the C++ code for my program:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <ctime>
using namespace std;

// Folder that we are going to write notes in
string NPATH = "C:/home/notes/";

// Convert integer to string
string istr(int i)
  stringstream ss;
  ss << i;
  return ss.str();

// Convert time to displayable form with year, month, day, for example
// 2010-01-01. Always 10 characters long.
string formTime(struct tm * cur)
  char s[11];
  sprintf(s, "%04d-%02d-%02d",
    cur->tm_year + 1900, // Number of years since 1900
    cur->tm_mon + 1,     // Month, starting at 0
    cur->tm_mday);       // Day of month
  return s;

// Does the file at this path exist, or not?
bool existsFile(string path)
  ifstream ifs(path.c_str());
  return ifs;

void write(string data)
  // Get current time
  time_t curr_t = time(NULL);
  tm * curr = localtime(&curr_t);

  // 1 might be already occupied, or 2, so fill first unoccupied one
  int ext = 1;
  string filebase = NPATH + formTime(curr);
  string flocation;
    flocation = filebase + "_" + istr(ext) + ".txt";

  // Write everything to the file
  ofstream fout;;
  fout << data;

int main()
  stringstream ss;

  // Accept input until line is "save" or "exit"
  string s;
    if(s == "save") break;
    if(s == "exit") return 0;
    ss << s << '\n';

  // Write everything and exit
  return 0;

Random Math Problems (1)

May 2, 2010

Probably any of these problems would be too small to include in a blog post on their own, so it might be more efficient (?) to put several of them together into one post.

The problems are not mine, and the solutions are not mine. They are just interesting problems I’ve come across when studying for math olympiads.

I hope to publish more collections of these random math problems in the future. That’s why I’m appending (1) to this post.

Problem 1

(From the 2010 Fermat contest)

Spheres can be stacked together into a tetrahedron (triangular pyramid). Here’s a visual (not created by me, from Wikipedia):

Each of the spheres in the tetrahedron has a number written on it. The top sphere is 1, and the number of any sphere is the sum of the numbers on the spheres in the layer above.

An internal sphere is defined as a sphere that is not on the outside, or in other words, touching exactly three spheres in the layer above.

In a tetrahedron with 13 layers, what is the sum of the numbers on all of the internal spheres?


Let’s draw out a few layers of the tetrahedron.
Hosted by

Look for patterns.

There’s a few things that can be noticed-

  1. The numbers at the three corners of a layer are 1
  2. Any layer is highly symmetrical: in the last diagram the sequence (1 4 6 4 1) appears in the bottom row, as well as the left and right diagonals. We can rotate the tetrahedron and the numbers would still be the same.
  3. The numbers on the outside form Pascal’s triangle. The sequence (1 3 3 1) is the 4th row of Pascal’s triangle; (1 4 6 4 1) is the 5th, and so on.

The most important thing to look for is the fact that Pascal’s triangle appears in the tetrahedron.

Each row of Pascal’s triangle is one longer than the previous row. To calculate a row, overlap the previous row with the new row, like this:
Hosted by

Here the number in a purple box is the number to the top-right of it plus the number to the top-left of it:
Hosted by


Notice that each number in the top gets added into exactly two boxes at the bottom.

Therefore the sum of the numbers in the bottom is twice the sum of the numbers in the top. 1 + 3 + 3 + 1 = 8, and 1 + 4 + 6 + 4 + 1 = 16.

This applies to any two rows. The sum of any row is twice the sum of the previous row.

Since the sum of the first row is 1, the sum of the second is 2, the sum of the third 4, and so on. We can even express this as a formula. The sum of the nth row is:


A similar idea applies to the layers of the tetrahedron.

In Pascal’s triangle, each number gets added to two places in the next row.

The tetrahedron is like Pascal’s triangle, in three dimensions. Each sphere in the tetrahedron sits on top of three spheres in the layer under it. So each number gets added to three different numbers in the next row.

Thus the sum of the numbers in any layer of the tetrahedron is 3 times the sum of numbers in the previous layer.

A formula for the sum of the nth layer of the tetrahedron:


What we really want is a formula for the middle numbers, or internal spheres. The internal spheres are the spheres that are not on the outer layer.

We know the formula for the sum of the whole layer, and we know the formula for any of the three ‘sides’ of a layer.

Hosted by

The internal numbers would be the sum of the entire layer minus three times the sum of a side. To cover up for the three 1′s we’ve counted more than once, we add 3 to the result.

The formula for the sum of the internal numbers on the nth layer:

3^{n-1} - 3 \cdot 2^{n-1} + 3

The problem asks for the sum of the first to the thirteenth layer. Well, the first three layers don’t have any internal spheres so we start from the forth:

\begin{array}{l} \displaystyle\sum_{n=4}^{13} 3^{n-1} - 2^{n-1} + 3 \\ = (3^3 + 3^4 + \cdots + 3^{12}) \\ \quad - 3(2^3 + 2^4 + \cdots + 2^{12}) + 3 \cdot 10 \end{array}

We can use the sum of geometric series formula, or more easily calculate it by brute force. The answer would be 772626.

Problem 2

(From the 2008 Canadian Math Olympiad)
Hosted by

In quadrilateral ABCD, CM splits the quadrilateral into two parts of equal area. AN also splits the quadrilateral into two parts of equal area. AB is the longest side of the quadrilateral.

Prove that MN bisects DB.


I’m going to use the equal sign to mean two figures with equal areas, not two figures that are congruent.

The triangles \triangle ANB and \triangle MCB are both half of ABCD, so their areas are equal. Then \triangle ANB = \triangle MCB.

\triangle ANB can be split into \triangle ANM + \triangle MNB, and similarly \triangle MCB can be split into \triangle MCN + \triangle MNB.

We know that \triangle ANB = \triangle MCB. By subtraction, \triangle AMN = \triangle MCN.

The triangles \triangle AMN and \triangle MCN share a common base, MN. Because their areas are equal, the perpendicular from A to MN is equal to the perpendicular from C to MN. Therefore AC || MN.

Now we draw a line through D, parallel to AC and MN. We extend AB and BC to meet this line (and we draw a couple of additional lines):
Hosted by

Because XY || AC, \triangle ADC = \triangle AXC = \triangle AYC.

Here \triangle MCB = ADCM.

We can write ADCM as \triangle ADC + \triangle ACM. Since \triangle ADC = \triangle AXC, ADCN = \triangle XCM.

It follows that \triangle MCB = \triangle XCM, and XM = MB.

Similarly, ADCN = \triangle AYN. Then \triangle ANB = ADCN = \triangle AYN, and YN = NB.

Because XM = MB and YN = NB, the result follows that DK = KB.

Problem 3

(From the 2010 USAMO)

This problem actually appears in both the junior and senior USAMO taken about a week ago from time of writing. It’s problem 4 in the senior and problem 6 in the junior.

Hosted by

\triangle ABC is a right triangle. BD bisects \angle ABC, and EC bisects \angle ACB.

Prove that the lines [AB, AC, BI, ID, CI, IE] cannot all have integer lengths.


I was really surprised at how short and simple the solution can be for this problem.

Because \angle BAC = 90, \angle ABC + \angle ACB = 90 and \angle IBC + \angle ICB = 45 because of the angle bisectors.

Then \angle BIC = 180-45 = 135.

First we apply the pythagorean theorem:

BC^2 = AB^2 + AC^2

We then apply the Law of Cosines:

BC^2 = IB^2 + IC^2 - 2 \cdot IB \cdot IC \cdot \cos 135

Combining the two, and substituting -\frac{1}{\sqrt{2}} for \cos 135:

\begin{array}{c} AB^2 + AC^2 = IB^2 + IC^2 + 2 \cdot IB \cdot IC \cdot \frac{1}{\sqrt{2}} \\ \frac{2 \cdot IB \cdot IC}{AB^2 + AC^2 - IB^2 - IC^2} = \sqrt{2} \end{array}

This is absurd, if AB, AC, IB, and IC are all integers and nonzero.


Get every new post delivered to your Inbox.

Join 61 other followers