Dad’s nerd

My dad was thirty when I was born, so a few years ago I had the opportunity to send him this for his birthday. Happy Father’s Day in heaven, Dad!

A birthday greeting

(Stick with it, it’s worth it.)

The counting system we normally use is called “base ten.”  It uses ten distinct digits (zero through nine), and the columns of a multi-digit number are powers of ten.  The rightmost column is “ones” (1 is 10 to the power of 0), the next column is “tens” (10 to the power of 1), the next column is “hundreds” (10 to the power of 2), and so on.

Example: the number 412 is understood as “four hundreds plus one ten plus two ones.”

Base ten is convenient for humans, who have ten fingers to count on.  But it’s inconvenient for computers, which count using “bits,” each of which is a microscopic on-off switch.  This makes it more convenient for computers to count in “base two,” which uses two distinct digits (zero and one, corresponding to a bit that’s off or on).  The columns of a multi-digit base-two number are powers of two.  The rightmost column is still “ones” (because 2 to the power of 0 is 1) but the next column is “twos,” then “fours,” then “eights,” then “sixteens,” and so on.

Example: the base-two number 110011100 is understood as “one 256 plus one 128 plus one 16 plus one 8 plus one 4” (which is the same as the base-10 number 412, by the way).

As you can see, base two requires many more columns than base ten to express the same number.  Computers don’t care about that – but the people who work with computers do.  Base two counting is very inconvenient for them.  But converting back and forth between base 10 and base 2 is onerous, because even computer nerds don’t like doing unnecessary arithmetic.

One common solution is to deal not in base two or in base ten but in base eight.  Base eight uses eight distinct digits (zero through seven) and the columns of a base-eight number are “ones,” “eights,” “sixty-fours,” and so on.

You might think that adding yet another counting system is a needless complication, but the cool thing about base eight is that each group of three base-two digits always corresponds to the same base-eight digit:

Base twoBase eight
0000
0011
0102
0113
1004
1015
1106
1117

This makes converting between base two and base eight easy.  Just take three base-two digits at a time (from right to left) and replace them with their base-eight counterpart:

110011100 -> 110 011 100 -> 634 (which is the base-eight version of 412).

Base eight is often called “octal,” and base ten is often called “decimal.”  Now you have enough information to understand this old programmer’s joke:

Q: Why is Halloween like Christmas?
A: Because OCT 31 = DEC 25!

But we’re not done.  Base eight is handy, but not as handy as it can be, because as you probably know, computer memory is divided into bytes, and each byte is eight bits long.  You can’t evenly divide eight bits into groups of three.  And there’s some ambiguity when you string together multiple bytes in a row.  Suppose you’re dealing with these two bytes:

11010001  10011100

Should you group these sixteen bits into threes like this:

11 010 001  10 011 100 -> 321234 (base eight)

(where each byte is grouped into threes separately) or like this:

1 101 000 110 011 100 -> 150634 (base eight)

(where all sixteen bits are strung together and then separated into groups of three)?

To avoid these problems, it’s more common for computer folks to use not base two, not base ten, and not base eight, but base sixteen!  Base sixteen has sixteen distinct digits: zero through nine as in base ten, then A for a single-digit “ten,” B for a single-digit “eleven,” C for a single-digit “twelve,” D for “thirteen,” E for “fourteen,” and F for “fifteen.”  The columns of a base-sixteen number are “ones,” “sixteens,” “two-hundred-fifty-sixes,” and so on.

In base sixteen, 412 is written as 19C.  (One 256 plus 9 sixteens plus twelve.)

Like base eight, base sixteen – which is also called “hexadecimal” (or “hex” for short) – is easily converted to and from base two, because every group of four base-two digits corresponds to a base sixteen digit.

Base twoBase sixteen
00000
00011
00102
00113
01004
01015
01106
01117
10008
10019
1010A
1011B
1100C
1101D
1110E
1111F

And grouping base-two digits four at a time instead of three at a time makes it very natural to represent any eight-bit byte as a two-digit hexadecimal number.

11010001  10011100 -> D1 9C

Now for the punchline of this nerdy shaggy-dog story.  This year you are turning 80 and I am turning 50.  And DEC 80 = HEX 50!

This is the kind of thing that makes nerds like me turn cartwheels of joy.  And before you roll your eyes or shake your head, let me just remind you of who raised this particular nerd.

Happy birthday, Dad.  I love this numeric coincidence, but not as much as I love you.

Exciting coincidence!


California’s license-plate scheme is

digit-letter-letter-letter-digit-digit-digit

We can consider this as a number written with one base-10 digit followed by three base-26 digits (where A is 0, B is 1, C is 2, etc.) followed by three more base-10 digits. It’s easy to convert such a sequence to a pure base-10 number. For instance, 0AAA000 is 0. 0AAA001 is 1. 0AAA002 is 2. And so on up through 0AAA999, which is 999, and then to 0AAB000, which is 1,000. 0AAC000 is 2,000. 0AAZ000 is 25,000. 0AAZ999 is 25,999, and 0ABA000 is 26,000. And so on.

Here is a short Python function that does the conversion:

def plate_to_number(sequence):
  result = 0
  for character in sequence:
    if character.isdigit():
      result = result * 10 + int(character)
    elif character.isalpha():
      character = character.lower()
      result = result * 26 + (ord(character) - ord('a'))
  return result

My first license plate on moving to California in 1992 was 2ZZZ923, whose number value is 52,727,923. Now here’s the exciting coincidence: the number value of my current license plate, from 2007, is almost exactly double that (to within an error of 0.014%)!

Well, it’s exciting to nerds.

Have you herd?


[Cross-posted at facebook.com/bob.glickstein/posts/10151865534302377.]

Suppose there’s a disease that has a 50% chance of infecting you if you come into contact with it. Now suppose you come into contact with 10 people in one day. On average, 5 of them will be carrying the disease. Your odds of avoiding the disease are 50%×50%×50%×50%×50%, which is about 3%. In other words, you have a 97% chance of contracting it.

Now suppose you – and only you – get vaccinated. Let’s say it reduces your odds of infection, when exposed, from 50% down to 10%. Since no one else is vaccinated, when you come into contact with 10 people, it’s still the case that 5 are infected. Your odds of avoiding the disease are now 90%×90%×90%×90%×90%, or 59%. There is a 41% chance you’ll get sick. That’s a big improvement compared to 97%, but we can do a lot better.

Now suppose everyone gets vaccinated. Of the 10 people you come into contact with, on average only 1 will be infected. Your odds of getting sick are now only 10%.

That is the power of herd immunity.

64+8+2+1


We had no room on Dad’s birthday cake for 75 candles. But who needs 75 when you know binary?

Hung up


Men, if your penis is of average size or slightly above, and you’ve taken solace (while watching some well-hung stud in a porn film) in the thought that most other men are your size or smaller, mathematics and I are here to ruin your whole day.

After all, it’s not some hypothetical matchup against all other men that you’re interested in, is it? If you’re honest with yourself, what you really care about is whether yours is the biggest dick your partner’s ever had. And that’s where the bad news begins.

Suppose your size is exactly average; that you’re in the 50th percentile for penis length. That means that 50% of men are smaller than you, and 50% are bigger. Does this mean you have a fifty-fifty chance of blowing your lover’s mind? Only if your partner had one man before you. If your partner had two men before you, the odds of their both being smaller are 0.5×0.5, or 25%. If three, the odds they were all smaller are 0.5×0.5×0.5, or 12.5%. In other words, there’s an 87.5% chance — 7 chances in 8 — they’ve seen bigger.

Let’s say you’re one of the lucky ones in the 75th percentile. Your dick is bigger than that of three out of every four men you see. There’s still a 58% chance that your partner (who’s had three men before you) has seen bigger!

In order to have an even chance of having the biggest dick that a partner with three previous lovers has ever seen, you have to be in the 80th percentile for penis size (about 6.25 inches according to the condom manufacturer LifeStyles). But that’s just an even chance. To have a good chance — say, 90% — you have to be in the 97th percentile (about 7.5 inches). And that’s if your partner has had only 3 men before you. It’s not too unusual to be the fifth or tenth or twentieth man, especially of a partner who’s very desirable.

None of these numbers mean anything if you can’t get it up when the time comes, so now that I’ve given you the bad news — don’t think about it.

Fit-ness

Survival of the “Fit”test

A lower price wasn’t the Fit’s only advantage over the Prius. While car shopping I rented a Prius for a one-day extended test drive, ending up with three specific complaints:

  1. Visibility through the rear window is poor;
  2. The console’s large, animated engine-performance display is dangerously distracting;
  3. The keyless engine-start button is (a) unsafe with small children around but (b) too cool to disable with the child-safety lock.

More than a year ago I replaced my 1998 Honda Civic hatchback with a new Honda Fit. Fuel efficiency was a key decision criterion for me, and naturally I considered the Toyota Prius; but the Prius gets its best gas mileage in city driving, and at the time of my purchase most of my driving was on the highway, where the Fit’s efficiency was close to that of the Prius, at a much lower price.

I’ve been tracking my Fit’s fuel consumption on a spreadsheet for several months now and the trend is clear: its efficiency is consistently in the 35 MPG range. Nothing to sneeze at, especially given the dismal fuel economy of almost all other cars on the market; but disappointingly it falls short of the mileage I was getting with my Civic at the end, which occasionally exceeded 40 MPG — with the previous decade’s engine technology!

You can see the mileage I’m getting, fill-up-by-fill-up, in my Google Docs spreadsheet.

What are the odds?

Our PlayStation 3 is not just a gaming console; it is our entire living room entertainment delivery system. It has replaced our DVD and CD players, and with its front-facing USB port I don’t even need CD’s; I just load up a thumb drive with music, plug it in, and play.

I have a thousand songs on one of those thumb drives, and I always play them in “shuffle” mode. Yet it seems that there is always a lot of overlap between one listening session and another — the same songs that I heard yesterday are in today’s mix. You’d think that with a thousand songs to choose from, it would be a while before I hear the same song twice, unless there’s something not sufficiently random about the PlayStation’s song randomizer.

I was all prepared to fire off an indignant letter to Sony’s customer support department when I decided I first needed to understand exactly how unlikely was the overlap I was encountering.

Figure that a “listening session” includes twenty songs. There are 339,482,811,302,457,603,895,512,614,793,686,020,778,700 (339 duodecillion) different ways to choose twenty songs from a collection of a thousand. This result is given by the combinatorial formula:

n! / k!(n-k)!

where n is the number of items to choose from (1,000, in this case), k is the number of items to choose (20), and “!” is the “factorial” operator that means “multiply the preceding number by every other number between it and 1.” Five factorial, for instance, is written “5!” and is equal to 5×4×3×2×1, which is 120.

The combinatorial formula above is sometimes abbreviated “nCk,” pronounced “n choose k.” The very very big number is the result of calculating 1000 C 20.

So there is a vast number of possible listening sessions. But in how many ways can one listening session overlap with another? Let’s consider a second listening session that doesn’t overlap at all with the first. The way to think about this is that the first listening session “used up” twenty of the available songs, leaving 980 to choose from — specifically, 980 from which to choose 20, or 980 C 20, which is 225,752,650,356,644,030,123,857,337,771,499,346,518,885 (225 duodecillion).

So of the 339 duodecillion ways to choose 20 songs from a thousand, 225 duodecillion, or 66%, do not overlap — but that means that 34% do overlap. There is a one-in-three chance that at least one song in the second session will be the same as one in the first.

This was a stunning result to me. I never expected the odds of an overlap to be so high.

That doesn’t mean that the PlayStation is working correctly, necessarily; it’s my impression that I’m getting multiple-song overlaps, and I’m getting them much more than one-third of the time, so the PlayStation still may not be adequately randomizing its playlist. But this result does send me back to the drawing board to gather objective data about just how much overlap I am getting.

To the nerdth power

Nerd confession: I just realized that my son Archer, who is 4, and my stepdaughter Pamela, who just turned 27, both have ages that can be expressed in the form nn — Archer is 22 and Pamela is 33. Barring a major advance in gerontology research I regret to say it is unlikely any of us will ever see 44.

(Didn’t know that I had an adult stepdaughter? I haven’t mentioned her here before, but we added her to the cast a couple of seasons ago in a Cousin Oliver moment to boost our sagging ratings.)

Update: Oh drat, Pamela’s 26, not 27. What’s interesting about the relationship between her age and Archer’s now? Umm… Archer’s is the number of suits in a deck of playing cards, and Pamela’s is the number of red (or black) cards? Sorry, that’s the best I’ve got.

At this rate…

How do you like that — the same weekend that my blog turned two years old, my Google AdSense account — the little kickbacks I get every time one of you clicks on the ads that appear next to one of these posts — also passed a major milestone: I’ve earned ten dollars! At this rate I’ll be able to retire, when the time comes, on over one hundred AdSense dollars!

Come to think of it, that’s only if you consider my mounting AdSense balance to be an arithmetic progression. On the other hand, ten dollars is a thousandfold increase over my balance the last time I reported it almost two years ago. With just two data samples it’s impossible to tell whether the progression is arithmetic or geometric. If the latter, then my balance has been growing at better than 1% per day. At that rate, by the time I retire you will all bow before benevolent supreme dictator Bob and his 8.7 duodecillion dollars, mwa ha ha ha ha ha! Even if the dollar collapses, that oughta be worth something on eBay. Thanks, AdSense!