Wednesday, January 13, 2010

how to count sheep

In other words, a diatribe to make non-nerdy people feel smugly non-crazy, and make nerdy people feel cheerfully less lonely in their compulsive-calculation habits. Don't lie, I know you do it too.

I was raised a victim of the delusion that children need at least 11 or 12 hours of sleep a night, so aside from fine-tuning my night-light vision and becoming likely the first person to ever be elated at OSSM's 11pm bedtime (while my roommate rolled her eyes and said "bedtime? are you kidding me? I haven't had one of those since I was 6"), I became an expert at counting sheep.

The whole point of counting sheep is to occupy your brain just enough to distract from the stuff that normally would keep you awake, but not enough to keep you wake. Obviously counting by the natural numbers is insufficient for this task after about age 7. I can count in the background and maintain several hypothetical conversations in the foreground and mull over some math proofs in the middle ground until 5 in the morning without even yawning.

The next step is counting backwards. That's fine for another day or two of sleep. Around fourth grade I counted backwards from a thousand to 1 several times in one week, and then moved on.

Then comes counting by multiples, backwards and forwards. Here's where it get's interesting. Some multiples are obviously even easier than counting by 1's. (10s, 5s, etc.) To get rid of those you have to rule out numbers that have common factors with ten (since we live in base 10), because then the last digits in the sequence you're going over will have a shorter cycle, and that's too easy. For example, counting by 4's is just a pattern of 4 8 2 6 0 over and over. And for any multiple of 5, it's just 5 0 5 0... And 2 and 5 are the factors of 10.

You can also rule out anything above, say, 20. The numbers just get too big too fast. It definitely takes more than 40 numbers to put me to sleep, and I don't like keeping four digit numbers in my head. When it stops being a calculation game and starts being a memory game, it either becomes too distracting to let you sleep, or you forget your place and have to start over too frequently.

We can also rule out numbers that are a multiple of 10, plus or minus 1. Those are only a slight improvement over 10 and 1 themselves.

So now we're left with 3, 7, 13, and 17.

All of these will keep you entertained for a while. 3 is too easy on its own because you can mentally check whether you're on track as fast as you can calculate the next number (since the digits have to add up to a multiple of 3. I don't have any idea on the fly if 126 is a multiple of 7 but I definitely know it's a multiple of 3.) The solution to that is to start with 1 or 2 instead of 3.

7 is basically fine.

13 and 17 are refinements on 3 and 7 that add the minor step of adding an extra 10 each time. That'll put you to sleep for an extra couple of days.

Unfortunately, even this runs out of usefulness soon. 10+3 is still too easy and 17 has an annoyingly convenient pattern in which you only have to know the first 6 multiples, and then add 2 to each one (and 100) And then 4 (and 200) etc. (In fact, as far as this type of repeat-plus-a-constant problem goes, 17 is as bad as it possibly gets, since 101 is prime.) Once those six numbers, 0 17 34 51 68 85, are engrained in your head, the game devolves into, at most, adding or subtracting 7. Still, ten years later, I still start with 17's (starting with something other than 0 to make it vaguely more interesting, or going backwards) when mild insomnia hits.

After multiples, there are squares. This was riotous fun in middle school. Not only can you check your work by explicitly multiplying n*n, you can get from n*n to (n+1)*(n+1) by adding n and then n+1. Lots of minor little calculations to do to keep your brain humming along in low gear fairly constantly.

But this too has a problem. The problem is that 24 + 25 + 25 + 26 is exactly 100. So when you go from 24*24=576 to 25*25=625 to 26*26=676... well you see the problem, the last two digits are the same! And of course the symmetry keeps going (23*23=529, 27*27=729, etc.) That is, 25*25=625 is a turning point, after which you just go backwards with different leading digits. (And then you get to 50*50=2500 and start over at the beginning). So you only have to know 25 numbers, easy enough to memorize thoroughly in a few nights, and then repeat. Still, that's a big improvement over the 6 numbers you have to know to count by 17's.

(This habit also had an unexpected benefit on high school math contests, where you somewhat frequently get questions involving square numbers. Sure there's always a smart way to do the problem, but if you have them all memorized at least to 2500, it's faster to just look for the answer in the numbers...)

Beating these patterns into the ground in rotation (like letting land lie fallow) kept me sleeping until sleep deprivation in high school and college eliminated the need for it for a few years, but now, my new favorite is triangular numbers! (Numbers of bowling pins in any sized arrangement. 1, 3, 6, 10, 15, etc.) This again has the nice trait of being calculable both via an easy formula, n*(n+1)/2, and by transitioning from one to the next by adding n+1. It doesn't form a cycle until 100, and that's plenty to put me to sleep. It also gets bigger slower than squares and is a bit harder to backwards engineer which one you're on.

The Fibonacci sequence is ok if you don't care about accuracy. If you screw up once you'll never know (since the non-recursive formula involves square roots of 5...) It also involves a little bit too much memory since you soon have to remember 6 digits to get to the next one, instead of 3.

Digits of irrational numbers requires no brain energy whatsoever, don't even think about it. Unless you're figuring them out as you go, like the square root of 2 or something. I find this much too brain intensive to allow sleep.

Other ideas? I think triangular numbers may be the apotheosis of sheep counting.