Math Puzzle: Enumerating Combinatorial Result Sets
Warning: Big-time nerder alert! If you find overt nerdyness offensive, zone out now or just click right on through.
I’m neither a computer scientist not a mathematician (and it probably shows), but I’m curious enough to poke around a bit. Lately I’ve been having fun with combinatorics.
One of the programs I often write as I’m learning a new programming language is a cryptogram maker. A cryptogram is basically it a word puzzle where each letter of a piece of text has been replaced by another letter according to a randomized substitution cipher. Here’s an example:
BEFORE: The quick brown fox jumped over the lazy dogs.
AFTER : QGF JKHDY ZESRP WSV CKUIFN SOFE QGF BMXL NSTA.
LETTER : ABCDEFGHIJKLMNOPQRSTUVWXYZ
CYPHER : MZDNFWTGHCYBUPSIJEAQKORVLX
Anyway, I’ve long known the total number of possible cypher keys (supposing that any letter can be replaced with itself), but I’ve spent several boring church meetings thinking about another simple combinatorics problem. Of course, it’s probably pretty basic to one who has studied combinatorics, but I’ll put it to you just the same.
The question was:
How do I process any given cypher key so that an ordered ’solution number’ can be derived from it (or vice versa) without iterating through the possible cyphers (or solutions).
After having the answer suddenly dawn on me the other night, I now put you to the test. And to make it only slightly more interesting, the first person to comment with the answers and an accurately described algorithm (complete with the basic math behind it) wins a whopping $5 cash prize mailable by me. Note that just writing a script to cycle through does not count because the whole point is not to iterate through all the cyphers. Also, I shrunk the alphabet to make it nicer on you. :)
| Solution Number | Cypher |
|---|---|
| 1 | ABCDEFGHIJ |
| 2 | ABCDEFGHJI |
| 3 | ABCDEFGIHJ |
| 4 | ABCDEFGIJH |
| 5 | ABCDEFGJHI |
| 6 | ABCDEFGJIH |
| 7 | ABCDEFHGIJ |
| … | … |
| ? | HDICAGEJFB |
| … | … |
| 3096542 | ? |
| … | … |
| ? | JIHGFEDCBA |
Show your logic! (Hint you can easily do the math on half a sheet of paper once you know the algorithm.)
Aside: This is not a particularly problematic problem (since I really had no need for a solution), but the math is fun just the same. I tried to think of a story problem that would make the math more compelling and less numerically intensive (without truncating the alphabet), but I sort of got bored of writing it. Maybe I’ll share what I came up with later.
If you liked this post, you may want to subscribe to my RSS feed. Thanks for visiting!
I had the opportunity to see the Cannon, Leavitt, and Chaffetz campaign speeches at both the Utah County and Utah State Republican Conventions. When it became clear through successive rounds of voting at the state convention that David Leavitt wasn’t going to win and that even Cannon would probably lose outright to Chaffetz at convention, all sorts of funny business started happening. It was like watching a large wounded animal give its last throws of life before submitting to defeat.