Saturday, September 15, 2012

In which many thousands of Facebookers can't think outside the square (yet some can)

Disclaimer: this is going to come across as very self-righteous and elitist to everyone who hasn't taken a college-level course in math, and pretentious/sloppy/arrogant to everyone else. So sue me, I'm inebriated and need an excuse to add a post to this blog. Tomorrow I'll probably regret it, considering how it's not a good idea to drink and derive.


A recent brain teaser has been making the rounds on Facebook. Take a look at the screenshot I made of it. I mean, sweet Jesus, that averages over 1.3 comments per second. I congratulate The Inquisitr for finding a very easy way to draw hundreds of thousands of eyes in one direction.

To be fair, I noticed at least one person in each 100+ swath of comments who got it right. Now, as for the puzzle itself, we can strain ourselves looking at the figure in every way imaginable, or we can use...MATH! Here's the comment I tossed into ocean (and subsequently edited, to remove length units from what should be dimensionless expressions):
Squares of length L1: 4^2
Squares of length L2: 2
Squares of length L2/2: 8
Squares of length L1*2: (4-2+1)^2 = 3^2
Squares of length L1*3: (4-3+1)^2 = 2^2
Squares of length L1*4: 1

All in all, if my drunken arithmetic is correct, that would be a total of 40 squares.
Here's what I meant by $L_1$ and $L_2$:
$L_1$
The squares of which there are four in each direction in the large "containing" square
$L_2$
(Which I later discovered was of equal length to L1) the two squares that are "superimposed" above and below the center of the figure. Whatever, I didn't hold a ruler up to the screen and was too lazy to use a pixel ruler.
$\frac{L_2}{2}$
Those $L_2$ squares are split into quadrants by the lines in the main 4x4 "grid"

Now, here's what I meant by the rest of it: if you think of a size of square (in the unit $L_1$) as having two degrees of freedom in position (horizontal and vertical) that's two in the exponent of the number of possible positions in a given direction (since all dimensions are the same, stick 'em all together as factors and it's a power of that one number: the length). Now, in this grid, it takes only a little observation to note that in any given direction, a square of a round number of units in length can occupy a number of positions one greater than the number of units in the grid minus its own length. Square that number, and voila, the number of squares of that length in the figure.

Take a square of size 2, for instance. Allow it to sit on an edge. There are two positions it could scoot over to (the two more units to the other edge), so with the position it is in, that makes three. A total of the grid size (4) minus the length of the square (2) plus the position it occupies (1), making $N_{L_i}=(4-i+1)^2$. For the squares composed of multiple other squares in the grid, therefore, we have:

\[ N_{tot}=\sum_{i=1}^{4}{(4-i+1)^2} \]

Combined with the other squares (the two "superimposed" squares that are each cut into four more squares by grid lines (making a total of 8+2 = 10 squares) this gives us a total of 40. Now why, pray tell, did I think of figuring it out this way? Countless times when I did math homework, each time learning new techniques, I contemplated in hindsight how I had always done things the hard way before then, and how, if I had taken sufficient time to study the problem, I could have been able to understand it in a broader and more abstract sense. This is the essence of most mathematics (and physics, for that matter): to use such understanding to generalize problems into timeless kernels of fact that can be efficiently re-used for all problems that fall into the same form.

"An equation is for eternity."

Albert Einstein

Whether equations appear useful here and now is of no concern; the important fact remains that they exist and we've found them, so that should they ever be needed there is no need to re-invent them as proverbial wheels, nor to solve the problem at hand in a primitive and inefficient way. They're like tools. Don't Be a Primitive Pete.

The general application of the above expression is that given a square grid of arbitrary length n, the total number of squares in the grid is:

\[N_{tot} = \sum_{i=1}^{n}{(n-i+1)^2} \]

Note how the only effort required was to change 4 to "n". That's a lot less than straining one's eyes over a 100x100 grid of squares while the brain overheats from the menial tasks of counting and exclusivity handed to short-term memory.

So there you have it. Kids, listen to your math teachers, for the love of all that makes civilization great.

Monday, May 23, 2011

"mydata" : Python script for rsync shorthand

This script is for those messy ones of us who have copies of all their personal files on multiple different machines/storage devices but with a possibly different folder structure at each location, and want to synchronize them using rsync. It's quick, it's simple and it makes rsync way easier to use.

Saturday, April 23, 2011

LUKS/XScreenSaver 1/2-factor authentication with a USB drive/password

Late last month (couldn't write about it then; had taxes, the physics GRE, and the spring Nasa EAP poster symposium to work on), I began a project: setting up Xubuntu Linux on an old Acer Aspire AS1691 for my dear old dad, who has always been quite open with me about his general dislike for computers, and his being a neo-luddite. But I wasn't just going to set up a user-friendly GNU/Linux environment for him on the thing: I made it my goal to make it secure and easy to use at the same time.

Monday, April 4, 2011

If you forgot your TrueCrypt passphrase but can remember the mnemonic...

A number of months ago this happened to me. Then I wrote this script, named it johnny.py, let it run overnight, and it found my passphrase. (BTW its name is inspired by John The Ripper; I'm not much of a Keanu fan). Feed it the class of all possible passwords that might correspond to your passphrase in the form of a space-delineated list, based on your password's mnemonic (each list a class of possible characters, i.e. aA@4 for the letter "A"), and it will iterate over every permutation.