The other day I saw this post. Although I’m not interested in Java, I was struck by the magic number CAFEBABE
that marked the beginning of the structure. That got me wondering how many words can be made with the hexadecimal digits A-F
. Before you read further, ask yourself how you’d go about solving this problem.
Being a developer, my first thought was, “Well I’ll just write a quick Lisp program.” The only aspect I wasn’t sure of was whether I should use Common Lisp or Emacs Lisp. It was pretty easy to layout the general structure in either language.
Then I had that “DUH” moment when I realized I was working way too hard. The easy way to solve this problem is
grep -v [^a-fA-F] /usr/share/dict/words
which gave me the results
A | a | aa | Ab |
aba | abac | abaca | abaff |
abb | Abba | Abe | abed |
acca | accede | ace | ad |
Ada | Adad | adad | add |
Adda | adda | added | Ade |
ade | adead | ae | aface |
affa | B | b | ba |
baa | Bab | baba | babe |
bac | bacaba | bacca | baccae |
bad | bade | bae | baff |
be | Bea | bead | beaded |
bebed | bed | bedad | bedded |
bedead | bedeaf | Bee | bee |
beef | C | c | ca |
cab | caba | cabda | Caca |
cad | cade | caeca | caffa |
ce | cede | cee | D |
d | da | dab | dabb |
dabba | dace | dad | Dada |
dada | dade | dae | daff |
de | dead | deaf | Deb |
deb | decad | decade | dee |
deed | deedeed | deface | E |
e | ea | ebb | ecad |
Ecca | Ed | Edda | edea |
efface | F | f | fa |
Faba | Fabaceae | facade | face |
faced | fad | fade | faded |
fae | faff | fe | fed |
fee | feed |
Sadly, cafe
isn’t in the system dictionary on my MacBook but the method stands.
The moral here is that we developers should remember that not every problem is a nail. Now that I think about it, this is the exact same point that I made two years ago.