Thursday, December 20, 2012

Why Geeks Don't Like You: A Hint for United Way of Central Maryland

Like many others around here, I am fairly used to getting spammed about this that or the other United Way campaign at my JHU work email. I've made my peace with it, after all configuring a spam filter isn't all that complicated. Of course a more appropriate solution would be for the spam to stop, but I decided a while ago that it's not worth picking a fight over.

In any case, every now and then something from United Way gets through. Tonight I received an email from

Nicole Lipinski <>
asking me to please donate money like I had in previous years. Now I have actually never donated to United Way, ever. It's not like I don't believe in charities, I just prefer to donate to other charities, maybe even some that don't spam me. 
But what the heck, I thought I'd take the time to point out to someone at United Way how I feel about the spam I get: I hit reply and explained briefly and politely that I am not donating and that it would probably help them with the geekier population around JHU if they stopped spamming us. I was a little surprised when I got back the following:

550 No Such User Here

Huh? You can probably guess what happened next. In a slightly less friendly tone I contacted

to complain about them sending me email from a completely fictional email address, one of the hallmarks of any self-respecting spammer. Then what happened?

550 No Such User Here
550 No Such User Here

You better believe it. Never mind that RFC 2142 clearly states that both of these addresses have to exist if you run SMTP on your host. So the next thing I do is check their whois record where I find two more email addresses:

Of course I had little hope by now that they would follow RFC 1834 any better than they had followed RFC 2142, and predictably I got back two more of these:

550 No Such User Here
550 No Such User Here

I don't know what the IT people over there are thinking. Maybe something like "Those rules only apply to old-fashioned business organizations, but we're a lean-and-mean donation-gathering-machine so we don't have to follow those weird RFCs!" Whatever it is, I can pretty much guarantee that this kind of ignorance in setting up their email infrastructure does not reflect very kindly on them. At least not from where I sit: deep geekland. Now excuse me while I tighten up that spam filter a bit more.

Sunday, September 16, 2012

Those Curious Python Operators

Alright, so Python still surprises me every now and then. Here's a fun one that I stumbled across by accident today:
>>> 0 == 0 == 0
>>> 0 == 0 == 1
>>> 0 == 1 == 0
>>> 0 == 1 == 1
>>> 1 == 0 == 0
>>> 1 == 0 == 1
>>> 1 == 1 == 0
>>> 1 == 1 == 1
Did you expect that? I sure didn't. But I guess Python is famous for "special casing" its operators to avoid confusing beginners in several places. So they end up confusing people who know lots of other languages instead. Here's what I would have expected to happen (but Python only does this with explicit parenthesis):
>>> (0 == 0) == 1
Good times! :-D BTW, in case you were wondering, another place where Python does the "right thing" despite what you may expect coming from C and similar languages: 14 < i < 99 actually does the proper range check, and not by accident either.

Saturday, July 28, 2012

AVL Trees Turn 50

I am teaching 600.226: Data Structures as a summer session course right now, and we covered AVL Trees yesterday. As I was ranting about them I suddenly realized that they were first published in 1962, and here I am in 2012 still teaching them to my eager (and somewhat perplexed) students.

So blame my brain: I have never been able to develop a good intuition about red-black trees (which I gather is what "respectable" schools are supposed to teach). My favorite balanced trees are treaps anyway, because they take so little code yet perform so well. But I feel that I "owe" my students at least one deterministic balanced search tree, and 2-3(-4) trees are just so messy to implement. Hence AVL!

I started to wonder: Since AVL trees were published in 1962, were they the first efficient data structure for ordered sets or maps? So I did some checking, and here is what I found:

AVL Trees 1962
B-Trees 1970
Symmetric Binary B-Trees 1972
Finger Trees 1977
Red-Black Trees 1978
Splay Trees 1985
Treaps 1989

If we losen things up a bit and include things that either demand more of the data or provide fewer general operations, we could consider these as well:

Tries 1960
Heaps 1964

So as far as I can tell after a quick search, AVL Trees are indeed the oldest efficient way to maintain a dynamic ordered set or map. And since students still have some trouble implementing them today, I guess that means we either haven't made a lot of progress, or we should take our proverbial hats off and nod a quiet "Thanks!" to Adelson-Velskii and Landis for figuring out how balanced search trees should work before most of us were even born.

Thursday, April 26, 2012

One or two rolls in D&D-variants?

Let's look at how (simple) combat works in (classic) D&D variants. There's an attacker of a certain level and a defender with a certain armor class. The attacker makes a roll, modified to take into account the attacker's physical capabilities as well as the situation the attack is made in. If the attacker hits, the attacker rolls damage which the defender subtracts from hit points. Not very complicated, is it?

Note that there's one roll for the attack and one roll for damage if the attack succeeds, that's it. Specifically, the defender does not make a roll to see if the successful attack can be evaded somehow. (And neither is there a roll to avoid some of the damage.)

Now let's look at how (simple) spells work in (classic) D&D variants. There's a caster of a certain level and a target of a certain level. (There are spells in which one or the other level doesn't matter, but that's besides the point.) Provided the caster doesn't get distracted while casting, the spell will be cast successfully. Now the target gets to make a saving throw against the spell. If the saving throw fails, the full spell effect applies to the target; if the saving throw succeeds, only some or none of the effects apply to the target.

Note that there's again one roll, but this time the roll tells us whether the defense was successful. (There may also be a roll for damage made by the caster, ignore that.) Specifically, the caster does not make a roll to see if the spell worked or fizzled somehow.

But now look at surprise. Surprise! There is both a chance to be surprised and a chance to surprise someone else. Details vary by which version of D&D you're looking at, but they all seem to maintain that both sides get to roll for both things. Having both sides roll dice in this situation but not in the other two situations seems rather odd. (I have no problem with the fact that the first two use a d20 and the third uses a d6, that's not the point.)

There are other places where a "let's use two rolls" mechanic has crept into D&D, for example when trying to disarm someone: You have to hit, but then the defender gets a saving throw to avoid dropping their weapon. There are also places where two rolls actually make sense in a way, for example for spells that require touching the target with a successful attack.

Now some people may just not care and some may say "different mechanism for different tasks are a-okay" or something close to that. But for myself, I would prefer a clear line throughout the whole system: Either use two rolls consistently, or use a single roll consistently, but don't jump back and forth. Opinions?

History of Greyhawk Wars PDF

It's difficult to explain exactly why I've done this, but in any case: I grabbed the old "Official History of the Greyhawk Wars" document that TSR posted on AOL in 1995 and converted it to LaTeX. I am probably not the first to do this, but I couldn't find another version anywhere, only RTF and HTML versions. I think my PDF looks great and reads better than the other versions I've seen. I made one tiny change compared to the original: I moved a paragraph from one section to another to get a more decent layout. Let me know what you think!

Tuesday, April 3, 2012

Spell Progressions in D&D-variants

I've been reading some interesting stuff related to D&D-type roleplaying games recently. One thing I came across is spell progression: How do you translate from the wizard or cleric level to the number of spells of each spell level the character can cast? Apparently different incarnations of D&D used somewhat different tables over the years.

All of this reminded me that I never liked the spell progressions in D&D-type games: I never "got" them in the sense that they always seemed way too random to me. What was the unifying mechanic behind all these numbers? Hard to figure out, go ahead, try.

I use the following simple progression: 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 and so on and so forth. Read: You start spell level x with 1 spell, after one more level you gain a second spell, after two more levels you gain a third, after three more you gain a fourth, etc. And I use this for each spell level. Both wizards and clerics gain a new spell level every 2 class levels, and done: One simple rule explains it all.

Yes, there is some “fluctuation” in terms of which character levels get the most new spell levels, but it’s really not too bad to say “look, level 18 is really powerful because that’s where you realize the most about how the multiverse really works". And yes, there are certain levels where you gain absolutely nothing, especially as a cleric, but those are really high and I wouldn’t normally play there anyway.