Friday the 13th

This post was originally published on November 13, 2006 (which wasn’t actually a Friday). It has been edited for style and content.

The date made me wonder why a Friday the 13th earns special mention any time an event comes up on that day. Consider that there are twelve months in a year, and each one has a 13th which must fall on one of seven weekdays — there are more months than days of the week, so it’s entirely plausible that more than one of them could be Fridays.

Case in Point

If February 13th is a Friday on a common year, then March 13th would also be a Friday, falling exactly four weeks later. This proves that it’s entirely possible to have two in one year (two-in-a-row, even), but makes me wonder what the upper limit is.

Explanation

Assign each day of the week a numerical value, i.e. 0 = Sunday .. 6 = Saturday. Using this map, we can determine the day of the week that each 13th will fall on, given d, the day of the week for January 1st, and p, which equals 0 on a common year, and 1 on a leap year.

January 13th d + 12 (mod 7)
February 13th d + 43 (mod 7)
March 13th d + 71 + p (mod 7)
April 13th d + 102 + p (mod 7)
May 13th d + 132 + p (mod 7)
June 13th d + 163 + p (mod 7)
July 13th d + 193 + p (mod 7)
August 13th d + 224 + p (mod 7)
September 13th d + 255 + p (mod 7)
October 13th d + 285 + p (mod 7)
November 13th d + 316 + p (mod 7)
December 13th d + 346 + p (mod 7)

The numerical offsets above represent the number of days after January 1st that the thirteenth of each month occurs. If we apply modulo 7 to these offsets, this will give us the day-of-the-week offset from our starting day, d:

common year { 5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3 }
leap year { 5, 1, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }

In other words, in a common year in which January 1st is a Monday (1), then January 13th will be Saturday (1 + 5 = 6), February 13th will be a Tuesday (1 + 1 = 2), etc.

Conclusion

To answer the original question, it’s obvious that the most frequent day-of-the-week offset is 1 on a common year and 5 on a leap year, both of which occur thrice. Therefore it is possible to have up to three Friday the 13ths in one year.

So what’s the next year we’ll have three? If 1 is the most common offset, we want to take 5 (Friday) - 1 = 4 (Thursday) and find the next common year that starts on Thursday, or similarly take 5 (Friday) - 5 = 0 (Sunday) and find the next leap year that starts on Sunday. These turn out to be 2009 (February 13th, March 13th, November 13th) and 2012 (January 13th, April 13th, July 13th).

· · ·

A Grue in Starbucks

Earlier today I stopped by a Starbucks in Albany, NY while waiting for my girlfriend’s class to end. Not far from where I sat, a twenty-something-year-old man sat at a table with his Apple laptop, scribbling on some sheets of paper.

Certainly that describes a large percentage of the Starbucks clientele, but I’ll risk it and say that this guy was probably the only person using a PowerBook 180 circa 1992.

I talked to him briefly before leaving; he was playing the Infocom text adventure Suspect. In it, you play as a costumed partygoer who is suspected of the murder of another guest. The Starbucks adventurer was carefully drawing out the room layout as a graph of connected and meticulously labeled boxes, trying to get his bearings in the virtual environment woven by text.

I used to play other Infocom mystery games when I was younger, though the only one I ever beat was Moonmist1. That said, I recently downloaded A Mind Forever Voyaging on James’s recommendation; I’m using DOSBox to run an old copy of it since my ICBM can’t run the Classic version he sent me a while back.


  1. Trivia: At the very beginning of Moonmist, a character asks you what your favorite color is. Invariably, the guest bedroom is painted that color (what a coincidence). But don’t think that choosing blue over yellow is inconsequential — it actually determines the solution of the mystery! 

· · ·

ClearPlay

I just saw a commercial for ClearPlay, a DVD player that will automatically skip over “sex, violence, and profanity” in pre-existing DVDs.

The evidence is overwhelming that content in entertainment—particularly violence—can have a damaging impact on children. It is easy enough for the studios to suggest kids not see any of these movies. Unfortunately, two thirds of MPAA fare is rated R. Most of the rest is PG-13, where the standards have slipped over time, and where studios routinely spend $30 million or more on marketing that is often aimed at children. ClearPlay is simply a tool that parents can use to help reduce content they might find objectionable. Finally, ClearPlay is an ideal solution that is used by families in the home, and doesn’t require limits on content the studios develop.

At the time of writing, 2,530 supported movies are censored for

  • Violence
    • Strong Action Violence
    • Gory / Brutal Violence
    • Disturbing Images
  • Sex and Nudity
    • Sensual Content
    • Crude Sexual Content
    • Nudity
    • Explicit Sexual Situations
  • Language
    • Vain Reference to Deity
    • Crude Language and Humor
    • Ethnic and Social Slurs
    • Cursing
    • Strong Profanity
    • Graphic Vulgarity
  • Other
    • Explicit Drug Use

On the website, they also provide extra “Parental Advisories,” warning parents about content that might be objectionable but doesn’t fit in the above categories. Advisories cover taboos such as “revealing clothing,” “implied premarital sex,” “bar environment,” “intense life or death situations,” and “dysfunctional relationships,” among dozens if not hundreds of others.

Censorship on a Thumbdrive

The service works by having you download “Filters” to a CD or thumbdrive, which is read by a ClearPlay-compatible DVD player. A Filter contains the start time and duration of censorable scenes, along with which categories the scene falls into. A single-movie Filter takes up about 136 KB, while a twenty-movie one takes about 260 KB, leaving about 7 KB per movie.

I downloaded a few Filters and tried my hand at figuring out how they tick. I don’t think they’re encrypted (or at least, with anything too strong), but they’re certainly not easy to read. They come in two flavors, CP2 and CPF. According to the License Agreement (which I violated by “attempt[ing] to … reverse engineer”), the CPF files are read by “RCA DVD players with model numbers DRC232N and DRC232NS and/or MaxPlay DVD Modem players” exclusively.

If I cracked how the files worked, I’d rewrite all of the Filters to skip to the censored content, playing only a montage of violence and nudity. Think how much better most movies would be.

· · ·

Internet Sharing on Leopard

I’m trying to fix up my stylesheet so I can post code and assembly more neatly.

Now that my Spring semester is over, I’ll be at home for the next 15 weeks or so. It’s a long enough time that I dedicated several hours today to setting up my workstation. At school I use my MacBook Pro exclusively, but while at home I like to multitask on my recently-upgraded iMac G5. I set it up with teleport and AirFoil, and it’s just like I plugged a third display in. (I can even turn on distcc to compile Universal Binaries faster.)

Since my parents use laptops exclusively, the home network is powered by a 802.11g Linksys wireless router. It’s fast enough for my MacBook Pro to enjoy fast, albeit sometimes intermittent, ‘net access. Unfortunately, the iMac G5 doesn’t have AirPort, and at the moment I don’t have a wireless USB adapter. It seemed like the perfect opportunity to try out OS X’s Internet Sharing.

Misadventures with Bluetooth

My first thought was that I have an unused Bluetooth USB adapter I bought on impulse. OS X seems to like it, so I thought I’d try sharing my AirPort connection over the Bluetooth PAN network device I activated under the “Advanced” sheet of the Bluetooth preference pane.

Unfortunately, though the service was offered, the iMac G5 didn’t want to connect to the MacBook Pro’s network. The menu item for it is grayed out. Google didn’t find me any valuable information to speak of. I’ll post back if I dig anything up later; this isn’t the first time I’ve tried (and failed at) sharing an Internet connection with another Mac over Bluetooth.

The Wired Route

Since the computers are only inches apart, I dug out a two-foot Ethernet cable and ran it between them, then told the MacBook Pro to share its connection through it. No luck, though, as the iMac G5 got a self-assigned IP address. Confused, I turned to the Console on the MacBook Pro and saw this repeated every ten seconds:

com.apple.launchd[1] (com.apple.InternetSharing[5303]) Exited with exit code: 1
com.apple.launchd[1] (com.apple.InternetSharing) Throttling respawn: Will start in 10 seconds

Apparently, the whenever the Internet Sharing daemon exits the system just tells it to relaunch. Needless to say, this doesn’t resolve the issue of why it quit in the first place, and just leads to an endless loop.

Manual Override

The locate command tells me that InternetSharing is in /usr/libexec/, and also that there’s a manpage on the program. The latter, in turn, tells me that the -d flag prints out debug details:

$ sudo /usr/libexec/InternetSharing -d
InternetSharing[5205]: InternetSharing starting
/etc/bootpd.plist is empty/missing
InternetSharing[5205]: 802.1X is active - exiting

I’m not entirely sure why it’s complaining about 802.1X — it shouldn’t be active at home, and I went ahead and removed all of my 802.1X profiles in the Network preference pane. This didn’t stop the daemon from complaining and stubbornly refusing to stay open.

Determined to fix the problem, I pulled out a disassembler and looked for the logic that prints out the “802.1X is active” line:

0x5906 movl 0x00007274,%eax
0x590b calll 0x00004f52 Anon42
0x5910 testb %al,%al
0x5912 je 0x00005930
 
0x5914 movl $0x00006ed5,0x04(%esp) 802.1X is active - exiting
0x591c jmpl 0x00005378

The code calls some function Anon42 which returns a boolean value of whether or not 802.1X is active. If so, it jumps to a routine that prints out and exits the program. If we altered the instruction at 0x5912 to be an unconditional jump, the program would run regardless of the state of 802.1X.

Now, there’s undoubtedly a good reason for performing this check, but since it was behaving erroneously, I went ahead and applied the patch and tried sharing again. I’m happy to report that the daemon stays open and shares the Internet connection with the iMac just fine.

Fat Pipe

To give you an idea of the relative speeds of the connections:

MacBook Pro
iMac G5

It looks like we add 20 ms to our ping and cut back the download rate by 2 MBits/sec, but otherwise the speeds are, in my opinion, respectable.